Skip to content

Commit b64ea83

Browse files
committed
tree: prevent adding children to catchAlls
Fixes #172
1 parent 4fa1cc7 commit b64ea83

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

tree.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func (n *node) addRoute(path string, handle Handle) {
146146

147147
// Check if the wildcard matches
148148
if len(path) >= len(n.path) && n.path == path[:len(n.path)] &&
149+
// Adding a child to a catchAll is not possible
150+
n.nType != catchAll &&
149151
// Check for longer wildcard, e.g. :name and :names
150152
(len(n.path) >= len(path) || path[len(n.path)] == '/') {
151153
continue walk

tree_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ func TestTreeCatchAllConflict(t *testing.T) {
332332
{"/src/*filepath/x", true},
333333
{"/src2/", false},
334334
{"/src2/*filepath/x", true},
335+
{"/src3/*filepath", false},
336+
{"/src3/*filepath/x", true},
335337
}
336338
testRoutes(t, routes)
337339
}

0 commit comments

Comments
 (0)