fix(all): use url.ParseRequestURI instead of just url.Parse where necessary

This commit is contained in:
Trong Huu Nguyen
2023-02-10 14:57:55 +01:00
parent f4bba075a6
commit 2f6a3682d9
4 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -137,7 +137,7 @@ func (h Handler) defaultErrorResponse(w http.ResponseWriter, r *http.Request, st
}
func (h Handler) customErrorRedirect(w http.ResponseWriter, r *http.Request, statusCode int) error {
override, err := url.Parse(h.GetErrorPath())
override, err := url.ParseRequestURI(h.GetErrorPath())
if err != nil {
return err
}
+1 -1
View File
@@ -36,7 +36,7 @@ func CanonicalRedirect(r *http.Request) string {
return ingressPath
}
parsed, err := url.Parse(redirect)
parsed, err := url.ParseRequestURI(redirect)
if err != nil {
// Silently fall back to ingress path
return ingressPath
+10
View File
@@ -102,6 +102,16 @@ func TestCanonicalRedirect(t *testing.T) {
value: "/path?gnu=notunix",
expected: "/path?gnu=notunix",
},
{
name: "relative path",
value: "path",
expected: "/some-path", // should fall back to default path
},
{
name: "relative path with query parameters",
value: "path?gnu=notunix",
expected: "/some-path", // should fall back to default path
},
{
name: "url encoded path",
value: "%2Fpath",
+1 -1
View File
@@ -119,7 +119,7 @@ func ParseIngress(ingress string) (*Ingress, error) {
return nil, fmt.Errorf("ingress cannot be empty")
}
u, err := url.Parse(ingress)
u, err := url.ParseRequestURI(ingress)
if err != nil {
return nil, err
}