Proxify empty URL should not crash
This commit is contained in:
parent
c0eab5ebc5
commit
abe568b5b3
2 changed files with 27 additions and 1 deletions
|
@ -220,6 +220,29 @@ func TestProxyFilterWithSrcset(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProxyFilterWithEmptySrcset(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("PROXY_IMAGES", "all")
|
||||||
|
|
||||||
|
var err error
|
||||||
|
parser := config.NewParser()
|
||||||
|
config.Opts, err = parser.ParseEnvironmentVariables()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf(`Parsing failure: %v`, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := mux.NewRouter()
|
||||||
|
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||||
|
|
||||||
|
input := `<p><img src="http://website/folder/image.png" srcset="" alt="test"></p>`
|
||||||
|
expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" srcset="" alt="test"/></p>`
|
||||||
|
output := ImageProxyRewriter(r, input)
|
||||||
|
|
||||||
|
if expected != output {
|
||||||
|
t.Errorf(`Not expected output: got %s`, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProxyFilterWithPictureSource(t *testing.T) {
|
func TestProxyFilterWithPictureSource(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("PROXY_IMAGES", "all")
|
os.Setenv("PROXY_IMAGES", "all")
|
||||||
|
|
|
@ -14,5 +14,8 @@ import (
|
||||||
|
|
||||||
// ProxifyURL generates an URL for a proxified resource.
|
// ProxifyURL generates an URL for a proxified resource.
|
||||||
func ProxifyURL(router *mux.Router, link string) string {
|
func ProxifyURL(router *mux.Router, link string) string {
|
||||||
|
if link != "" {
|
||||||
return route.Path(router, "proxy", "encodedURL", base64.URLEncoding.EncodeToString([]byte(link)))
|
return route.Path(router, "proxy", "encodedURL", base64.URLEncoding.EncodeToString([]byte(link)))
|
||||||
}
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue