}
}
+// Issue 73688
+func TestServeMuxHandlerTrailingSlash(t *testing.T) {
+ setParallel(t)
+ mux := NewServeMux()
+ const original = "/{x}/"
+ mux.Handle(original, NotFoundHandler())
+ r, _ := NewRequest("POST", "/foo", nil)
+ _, p := mux.Handler(r)
+ if p != original {
+ t.Errorf("got %q, want %q", p, original)
+ }
+}
+
// Issue 24297
func TestServeMuxHandleFuncWithNilHandler(t *testing.T) {
setParallel(t)
var u *url.URL
n, matches, u = mux.matchOrRedirect(host, r.Method, path, r.URL)
if u != nil {
- return RedirectHandler(u.String(), StatusMovedPermanently), u.Path, nil, nil
+ return RedirectHandler(u.String(), StatusMovedPermanently), n.pattern.String(), nil, nil
}
if path != escapedPath {
// Redirect to cleaned path.
path += "/"
n2, _ := mux.tree.match(host, method, path)
if exactMatch(n2, path) {
- return nil, nil, &url.URL{Path: cleanPath(u.Path) + "/", RawQuery: u.RawQuery}
+ // It is safe to return n2 here: it is used only in the second RedirectHandler case
+ // of findHandler, and that method returns before it does the "n == nil" check where
+ // the first return value matters. We return it here only to make the pattern available
+ // to findHandler.
+ return n2, nil, &url.URL{Path: cleanPath(u.Path) + "/", RawQuery: u.RawQuery}
}
}
return n, matches, nil