From 3572bc9deaf24271af3d464cd4f55b4f652d3f99 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Wed, 4 Dec 2019 07:56:01 +0800 Subject: [PATCH] fix maxParams bug (#2166) --- tree.go | 4 ++++ tree_test.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/tree.go b/tree.go index 1187f3f64a..b46ec828d8 100644 --- a/tree.go +++ b/tree.go @@ -357,6 +357,10 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle maxParams: 1, fullPath: fullPath, } + // update maxParams of the parent node + if n.maxParams < 1 { + n.maxParams = 1 + } n.children = []*node{child} n.indices = string(path[i]) n = child diff --git a/tree_test.go b/tree_test.go index e6e2886590..0fe2fe0011 100644 --- a/tree_test.go +++ b/tree_test.go @@ -368,6 +368,13 @@ func TestTreeCatchAllConflictRoot(t *testing.T) { testRoutes(t, routes) } +func TestTreeCatchMaxParams(t *testing.T) { + tree := &node{} + var route = "/cmd/*filepath" + tree.addRoute(route, fakeHandler(route)) + checkMaxParams(t, tree) +} + func TestTreeDoubleWildcard(t *testing.T) { const panicMsg = "only one wildcard per path segment is allowed"