Skip to content

Commit

Permalink
Fixed processing of multiple queries for the same path
Browse files Browse the repository at this point in the history
  • Loading branch information
BlasterAlex authored and AlexVulaj committed Jan 22, 2024
1 parent 2b030fc commit 976b536
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
2 changes: 1 addition & 1 deletion route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 976b536

Please sign in to comment.