Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in the calculation of the maximum number of parameters #2166

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down