Skip to content

Commit

Permalink
fix maxParams bug (gin-gonic#2166)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou authored and ThomasObenaus committed Feb 19, 2020
1 parent 189bdc0 commit 3572bc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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

0 comments on commit 3572bc9

Please sign in to comment.