diff --git a/tree.go b/tree.go index 4da10331..5ab52816 100644 --- a/tree.go +++ b/tree.go @@ -166,7 +166,7 @@ walk: if n.nType != catchAll { pathSeg = strings.SplitN(pathSeg, "/", 2)[0] } - prefix := fullPath[:strings.Index(fullPath, pathSeg)] + n.path + prefix := fullPath[:strings.LastIndex(fullPath, path)] + n.path panic("'" + pathSeg + "' in new path '" + fullPath + "' conflicts with existing wildcard '" + n.path + diff --git a/tree_test.go b/tree_test.go index a1411315..0ad2d372 100644 --- a/tree_test.go +++ b/tree_test.go @@ -670,6 +670,7 @@ func TestTreeWildcardConflictEx(t *testing.T) { {"/who/are/foo/bar", "/foo/bar", `/who/are/\*you`, `/\*you`}, {"/conxxx", "xxx", `/con:tact`, `:tact`}, {"/conooo/xxx", "ooo", `/con:tact`, `:tact`}, + {"/whose/:users/:user", ":user", `/whose/:users/:name`, `:name`}, } for _, conflict := range conflicts { @@ -681,6 +682,7 @@ func TestTreeWildcardConflictEx(t *testing.T) { "/con:tact", "/who/are/*you", "/who/foo/hello", + "/whose/:users/:name", } for _, route := range routes {