1
0
Fork 0

Sanitise double slashes, and return nil in get() if a path continues but a node doesn't have children.

This commit is contained in:
Alexander Andreev 2023-07-23 23:19:58 +04:00
parent 5d6a3630c6
commit 33de30fe23
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 6 additions and 0 deletions

View File

@ -20,6 +20,8 @@ func newPath(path string) (path, error) {
return nil, errors.New("there can be only one catch-all (*) parameter in path")
}
path = strings.ReplaceAll(path, "//", "/")
parts := strings.Split(strings.TrimSuffix(path, "/"), "/")
parts[0] = "/"
@ -75,6 +77,10 @@ outer:
if pathLen > i+1 {
var paramNode *node
if len(curNode.children) == 0 {
break outer
}
for _, next := range curNode.children {
if next.endpoint == path[i+1] {
curNode = next