From 33de30fe2362d8a1f75389eb44d714e7e109a70c Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 23 Jul 2023 23:19:58 +0400 Subject: [PATCH] Sanitise double slashes, and return nil in get() if a path continues but a node doesn't have children. --- httpr.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/httpr.go b/httpr.go index 7e2a48d..d085c88 100644 --- a/httpr.go +++ b/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") } + 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