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: param router doesn't match param #978

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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
4 changes: 1 addition & 3 deletions pkg/route/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ func (r *router) insert(path string, h app.HandlersChain, t kind, ppath string,
if h != nil {
currentNode.handlers = h
currentNode.ppath = ppath
if len(currentNode.pnames) == 0 {
currentNode.pnames = pnames
}
currentNode.pnames = pnames
}
}
return
Expand Down
29 changes: 29 additions & 0 deletions pkg/route/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,32 @@ func TestTreeFindCaseInsensitivePath(t *testing.T) {
}
}
}

func TestTreeParamNotOptimize(t *testing.T) {
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
routes := [...]string{
"/:parama/start",
"/:paramb",
}
for _, route := range routes {
tree.addRoute(route, fakeHandler(route))
}
checkRequests(t, tree, testRequests{
{"/1", false, "/:paramb", param.Params{param.Param{Key: "paramb", Value: "1"}}},
{"/1/start", false, "/:parama/start", param.Params{param.Param{Key: "parama", Value: "1"}}},
})

// other sequence
tree = &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
routes = [...]string{
"/:paramb",
"/:parama/start",
}
for _, route := range routes {
tree.addRoute(route, fakeHandler(route))
}
checkRequests(t, tree, testRequests{
{"/1/start", false, "/:parama/start", param.Params{param.Param{Key: "parama", Value: "1"}}},
{"/1", false, "/:paramb", param.Params{param.Param{Key: "paramb", Value: "1"}}},
})
}
Loading