Sanitise double slashes, and return nil in get() if a path continues but a node doesn't have children.
This commit is contained in:
parent
5d6a3630c6
commit
33de30fe23
6
httpr.go
6
httpr.go
@ -20,6 +20,8 @@ func newPath(path string) (path, error) {
|
|||||||
return nil, errors.New("there can be only one catch-all (*) parameter in path")
|
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 := strings.Split(strings.TrimSuffix(path, "/"), "/")
|
||||||
|
|
||||||
parts[0] = "/"
|
parts[0] = "/"
|
||||||
@ -75,6 +77,10 @@ outer:
|
|||||||
|
|
||||||
if pathLen > i+1 {
|
if pathLen > i+1 {
|
||||||
var paramNode *node
|
var paramNode *node
|
||||||
|
if len(curNode.children) == 0 {
|
||||||
|
break outer
|
||||||
|
}
|
||||||
|
|
||||||
for _, next := range curNode.children {
|
for _, next := range curNode.children {
|
||||||
if next.endpoint == path[i+1] {
|
if next.endpoint == path[i+1] {
|
||||||
curNode = next
|
curNode = next
|
||||||
|
Loading…
Reference in New Issue
Block a user