Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conflict between param and exact path #2706

Merged
merged 7 commits into from May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions tree.go
Expand Up @@ -411,8 +411,14 @@ walk: // Outer loop for walking the tree
idxc := path[0]
for i, c := range []byte(n.indices) {
if c == idxc {
n = n.children[i]
continue walk
childWillWalkTo := n.children[i]

if strings.Split(childWillWalkTo.path, "/")[0] != strings.Split(path, "/")[0] && strings.HasPrefix(n.children[len(n.children)-1].path, ":") {
g1eny0ung marked this conversation as resolved.
Show resolved Hide resolved
continue
} else {
n = childWillWalkTo
continue walk
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tree_test.go
Expand Up @@ -142,6 +142,7 @@ func TestTreeWildcard(t *testing.T) {
"/src/*filepath",
"/search/",
"/search/:query",
"/search/gin-gonic",
"/user_:name",
"/user_:name/about",
"/files/:dir/*filepath",
Expand Down Expand Up @@ -169,6 +170,7 @@ func TestTreeWildcard(t *testing.T) {
{"/search/", false, "/search/", nil},
{"/search/someth!ng+in+ünìcodé", false, "/search/:query", Params{Param{Key: "query", Value: "someth!ng+in+ünìcodé"}}},
{"/search/someth!ng+in+ünìcodé/", true, "", Params{Param{Key: "query", Value: "someth!ng+in+ünìcodé"}}},
{"/search/gin", false, "/search/:query", Params{Param{"query", "gin"}}},
g1eny0ung marked this conversation as resolved.
Show resolved Hide resolved
{"/user_gopher", false, "/user_:name", Params{Param{Key: "name", Value: "gopher"}}},
{"/user_gopher/about", false, "/user_:name/about", Params{Param{Key: "name", Value: "gopher"}}},
{"/files/js/inc/framework.js", false, "/files/:dir/*filepath", Params{Param{Key: "dir", Value: "js"}, Param{Key: "filepath", Value: "/inc/framework.js"}}},
Expand Down