diff --git a/mux_test.go b/mux_test.go index 7f123f02..0845d7f7 100644 --- a/mux_test.go +++ b/mux_test.go @@ -2116,6 +2116,24 @@ func TestMultipleDefinitionOfSamePathWithDifferentMethods(t *testing.T) { } +func TestMultipleDefinitionOfSamePathWithDifferentQueries(t *testing.T) { + emptyHandler := func(w http.ResponseWriter, r *http.Request) {} + + r := NewRouter() + r.HandleFunc("/api", emptyHandler).Queries("foo", "{foo:[0-9]+}").Methods(http.MethodGet) + r.HandleFunc("/api", emptyHandler).Queries("bar", "{bar:[0-9]+}").Methods(http.MethodGet) + + req := newRequest(http.MethodGet, "/api?bar=4") + match := new(RouteMatch) + matched := r.Match(req, match) + if !matched { + t.Error("Should have matched route for methods") + } + if match.MatchErr != nil { + t.Error("Should have no error. Found:", match.MatchErr) + } +} + func TestErrMatchNotFound(t *testing.T) { emptyHandler := func(w http.ResponseWriter, r *http.Request) {} diff --git a/route.go b/route.go index cb89ebb8..b6582dae 100644 --- a/route.go +++ b/route.go @@ -87,7 +87,7 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool { return false } - if match.MatchErr == ErrMethodMismatch && r.handler != nil { + if match.MatchErr != nil && r.handler != nil { // We found a route which matches request method, clear MatchErr match.MatchErr = nil // Then override the mis-matched handler