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

Bugfix for the FullPath feature #1919

Merged
merged 4 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,15 @@ func TestRouteContextHoldsFullPath(t *testing.T) {

// Test routes
routes := []string{
"/",
"/simple",
"/project/:name",
"/",
"/news/home",
"/news",
"/simple-two/one",
"/simple-two/one-two",
"/project/:name/build/*params",
"/project/:name/bui",
}

for _, route := range routes {
Expand Down
9 changes: 8 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func (n *node) addRoute(path string, handlers HandlersChain) {
n.priority++
numParams := countParams(path)

parentFullPathIndex := 0

// non-empty tree
if len(n.path) > 0 || len(n.children) > 0 {
walk:
Expand Down Expand Up @@ -155,7 +157,7 @@ func (n *node) addRoute(path string, handlers HandlersChain) {
children: n.children,
handlers: n.handlers,
priority: n.priority - 1,
fullPath: fullPath,
fullPath: n.fullPath,
}

// Update maxParams (max of all children)
Expand All @@ -171,13 +173,15 @@ func (n *node) addRoute(path string, handlers HandlersChain) {
n.path = path[:i]
n.handlers = nil
n.wildChild = false
n.fullPath = fullPath[:parentFullPathIndex+i]
}

// Make new node a child of this node
if i < len(path) {
path = path[i:]

if n.wildChild {
parentFullPathIndex += len(n.path)
n = n.children[0]
n.priority++

Expand Down Expand Up @@ -211,6 +215,7 @@ func (n *node) addRoute(path string, handlers HandlersChain) {

// slash after param
if n.nType == param && c == '/' && len(n.children) == 1 {
parentFullPathIndex += len(n.path)
n = n.children[0]
n.priority++
continue walk
Expand All @@ -219,6 +224,7 @@ func (n *node) addRoute(path string, handlers HandlersChain) {
// Check if a child with the next path byte exists
for i := 0; i < len(n.indices); i++ {
if c == n.indices[i] {
parentFullPathIndex += len(n.path)
i = n.incrementChildPrio(i)
n = n.children[i]
continue walk
Expand Down Expand Up @@ -369,6 +375,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
// insert remaining path part and handle to the leaf
n.path = path[offset:]
n.handlers = handlers
n.fullPath = fullPath
}

// nodeValue holds return values of (*Node).getValue method
Expand Down