mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
fix: avoid panic in case-insensitive wildcard lookup
This commit is contained in:
parent
863f984990
commit
70f8cc6159
2 changed files with 29 additions and 1 deletions
28
tree_test.go
28
tree_test.go
|
|
@ -901,6 +901,34 @@ func TestTreeInvalidNodeType(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFindCaseInsensitivePathWithStaticAndParamRoutesDoesNotPanicOnMiss(t *testing.T) {
|
||||
tree := &node{}
|
||||
routes := [...]string{
|
||||
"/:user/:repo/info/refs",
|
||||
"/healthz",
|
||||
"/api/db/data",
|
||||
"/api/db/sum",
|
||||
}
|
||||
|
||||
for _, route := range routes {
|
||||
tree.addRoute(route, fakeHandler(route))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("unexpected panic while looking up missing path: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
if out, found := tree.findCaseInsensitivePath("/does-not-exist", true); found || out != nil {
|
||||
t.Fatalf("expected missing path lookup to return no match, got %q, %t", string(out), found)
|
||||
}
|
||||
|
||||
if out, found := tree.findCaseInsensitivePath("/does-not-exist", false); found || out != nil {
|
||||
t.Fatalf("expected missing path lookup without trailing slash fix to return no match, got %q, %t", string(out), found)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeInvalidParamsType(t *testing.T) {
|
||||
tree := &node{}
|
||||
// add a child with wildcard
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue