Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,22 @@ func (r *Router) Find(method, path string, c Context) {

// update indexes/search in case we need to backtrack when no handler match is found
paramIndex++
if !currentNode.isLeaf {
i := 0
l := len(search)

for ; i < l && search[i] != '/'; i++ {
}
search = search[i:]
previousBestMatchNode = currentNode
if len(search) != 0 {
if child := currentNode.findStaticChild(search[0]); child != nil {
searchIndex = searchIndex + len(child.prefix)
currentNode = child
continue
}
}
}
searchIndex += +len(search)
search = ""

Expand Down
10 changes: 8 additions & 2 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,13 +1579,19 @@ func TestRouterAnyMatchesLastAddedAnyRoute(t *testing.T) {
assert.Equal(t, "/users/*/action*", c.Get("path"))
assert.Equal(t, "xxx/action/sea", c.Param("*"))

// if we add another route then it is the last added and so it is matched
r.Add(http.MethodGet, "/users/*/action/search", handlerHelper("case", 3))

// should not match incomplete route with wildcard but match previous one
r.Find(http.MethodGet, "/users/xxx/action/sea", c)
c.handler(c)
assert.Equal(t, "/users/*/action/search", c.Get("path"))
assert.Equal(t, "/users/*/action*", c.Get("path"))
assert.Equal(t, "xxx/action/sea", c.Param("*"))

// should match route with wildcard and static suffix
r.Find(http.MethodGet, "/users/xxx/action/search", c)
c.handler(c)
assert.Equal(t, "/users/*/action/search", c.Get("path"))
assert.Equal(t, "xxx/action/search", c.Param("*"))
}

// Issue #1739
Expand Down