Skip to content

Commit

Permalink
Fix Mux.Find returning partial path for failing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
joeriddles committed Sep 23, 2024
1 parent e470ce0 commit 5a7133e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 4 additions & 0 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ func (mx *Mux) Find(rctx *Context, method, path string) string {

rctx.RoutePath = mx.nextRoutePath(rctx)
subPattern := node.subroutes.Find(rctx, method, rctx.RoutePath)
if subPattern == "" {
return ""
}

pattern = strings.TrimSuffix(pattern, "/*")
pattern += subPattern
}
Expand Down
9 changes: 2 additions & 7 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1894,12 +1894,7 @@ func TestMuxFind(t *testing.T) {
}

tctx.Reset()
if r.Find(tctx, "GET", "/") != "/" {
t.Fatal("expecting to find pattern / for route: GET /")
}

tctx.Reset()
if r.Find(tctx, "GET", "/nope") == "/nope" {
if r.Find(tctx, "GET", "/nope") != "" {
t.Fatal("not expecting to find pattern for route: GET /nope")
}

Expand All @@ -1909,7 +1904,7 @@ func TestMuxFind(t *testing.T) {
}

tctx.Reset()
if r.Find(tctx, "HEAD", "/articles/10") == "/articles/{id}" {
if r.Find(tctx, "HEAD", "/articles/10") != "" {
t.Fatal("not expecting to find pattern for route: HEAD /articles/10")
}

Expand Down

0 comments on commit 5a7133e

Please sign in to comment.