-
Notifications
You must be signed in to change notification settings - Fork 56
Closed
Description
The following test uncovers an issue with the current implementation of httptreemux:
func TestRedirectEscapedPath(t *testing.T) {
router := NewContextMux()
testHandler := func(w http.ResponseWriter, r *http.Request) {}
router.GET("/:escaped/", testHandler)
w := httptest.NewRecorder()
u, err := url.Parse("/Test P@th")
if err != nil {
t.Error(err)
return
}
r := httptest.NewRequest(http.MethodGet, u.String(), nil)
router.ServeHTTP(w, r)
path, err := w.Result().Location()
if err != nil {
t.Error(err)
return
}
expected := "/Test%20P@th/"
if path.String() != expected {
t.Errorf("Given path wasn't escaped correctly.\n" +
"Expected: %q\nBut got: %q", expected, path.String())
}
}This is caused since in lookup, path is used for redirects but it still contains escaped characters. Then in redirect newUrl.String() is called which results in double encoded characters.
Metadata
Metadata
Assignees
Labels
No labels