diff --git a/core/router/router_wildcard_root_test.go b/core/router/router_wildcard_root_test.go index becfc398..c6f94305 100644 --- a/core/router/router_wildcard_root_test.go +++ b/core/router/router_wildcard_root_test.go @@ -67,7 +67,7 @@ func TestRouterWildcardDifferentPrefixPath(t *testing.T) { }}, } - testTheRoutes(t, tt, false) + testTheRoutes(t, tt, true) } func TestRouterWildcardAndStatic(t *testing.T) { @@ -117,7 +117,7 @@ func TestRouterWildcardRootMany(t *testing.T) { }}, } - testTheRoutes(t, tt, false) + testTheRoutes(t, tt, true) } func TestRouterWildcardRootManyAndRootStatic(t *testing.T) { diff --git a/core/router/trie.go b/core/router/trie.go index 658e21f5..0804e78a 100644 --- a/core/router/trie.go +++ b/core/router/trie.go @@ -127,26 +127,32 @@ func (tr *trie) insert(path string, route context.RouteReadOnly, handlers contex var paramKeys []string - for i, s := range input { + for _, s := range input { if len(s) == 0 { continue } c := s[0] - if len(s)-1 > i+1 && s[i+1] != '/' { // has next character and it's not slash. - // get the next character, if not slash then this is a parameter. + if len(s) > 1 { // has more than one character. + // get the next character, should be the name of the parameter. // E.g: // If /test/:param (or /test/*param) then it's dynamic. // If /test/: (or /test/*) then it's static. - if c == paramStartCharacter { - n.childNamedParameter = true - s = ParamStart - } else if c == wildcardParamStartCharacter { - n.childWildcardParameter = true - s = WildcardParamStart - if tr.root == n { - tr.hasRootWildcard = true + if isParam, isWildcard := c == paramStartCharacter, c == wildcardParamStartCharacter; isParam || isWildcard { + n.hasDynamicChild = true + paramKeys = append(paramKeys, s[1:]) // without : or *. + if isParam { + n.childNamedParameter = true + s = ParamStart + } + + if isWildcard { + n.childWildcardParameter = true + s = WildcardParamStart + if tr.root == n { + tr.hasRootWildcard = true + } } } }