1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-05 00:58:47 +02:00

refs #1412: Fix parent nodes for route insert on node split

This commit is contained in:
Roland Lammel
2019-10-16 21:52:10 +02:00
parent 616db6dbad
commit ccf6f1a77d
2 changed files with 149 additions and 55 deletions

View File

@ -136,6 +136,11 @@ func (r *Router) insert(method, path string, h HandlerFunc, t kind, ppath string
// Split node
n := newNode(cn.kind, cn.prefix[l:], cn, cn.children, cn.methodHandler, cn.ppath, cn.pnames)
// Update parent path for all children to new node
for _, child := range cn.children {
child.parent = n
}
// Reset parent node
cn.kind = skind
cn.label = cn.prefix[0]
@ -417,6 +422,10 @@ func (r *Router) Find(method, path string, c Context) {
if np == nil {
break // no further parent nodes in tree, abort
}
var str strings.Builder
str.WriteString(nn.prefix)
str.WriteString(search)
search = str.String()
nn = np
}
if cn != nil { // use the found "any" route and update path