Skip to content

Commit

Permalink
hotfix(wildpath): set user empty value (#47)
Browse files Browse the repository at this point in the history
* hotfix(wildpath): set user empty value

* fix(tree): modify tree ut
  • Loading branch information
1046102779 authored Mar 1, 2021
1 parent 0f5bbd6 commit f74be76
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion radix/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ walk:
return child.handler, false
case child.wildcard != nil:
if ctx != nil {
ctx.SetUserValue(child.wildcard.paramKey, copyString(path))
ctx.SetUserValue(child.wildcard.paramKey, "")
}

return child.wildcard.handler, false
Expand Down
2 changes: 1 addition & 1 deletion radix/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestTreeWildcard(t *testing.T) {
{"/cmd/test/", false, "/cmd/{tool}/", map[string]interface{}{"tool": "test"}},
{"/cmd/test", true, "", nil},
{"/cmd/test/3", false, "/cmd/{tool}/{sub}", map[string]interface{}{"tool": "test", "sub": "3"}},
{"/src/", false, "/src/{filepath:*}", map[string]interface{}{"filepath": "/"}},
{"/src/", false, "/src/{filepath:*}", map[string]interface{}{"filepath": ""}},
{"/src/some/file.png", false, "/src/{filepath:*}", map[string]interface{}{"filepath": "some/file.png"}},
{"/search/", false, "/search/", nil},
{"/search/someth!ng+in+ünìcodé", false, "/search/{query}", map[string]interface{}{"query": "someth!ng+in+ünìcodé"}},
Expand Down
2 changes: 1 addition & 1 deletion radix/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (t *Tree) Get(path string, ctx *fasthttp.RequestCtx) (fasthttp.RequestHandl
return t.root.handler, false
case t.root.wildcard != nil:
if ctx != nil {
ctx.SetUserValue(t.root.wildcard.paramKey, "/")
ctx.SetUserValue(t.root.wildcard.paramKey, "")
}

return t.root.wildcard.handler, false
Expand Down
2 changes: 1 addition & 1 deletion radix/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func Test_TreeRootWildcard(t *testing.T) {
tree.Add("/{filepath:*}", handler)

testHandlerAndParams(t, tree, "/", handler, false, map[string]interface{}{
"filepath": "/",
"filepath": "",
})
}

Expand Down

0 comments on commit f74be76

Please sign in to comment.