revert and update rules

This commit is contained in:
qm012 2021-07-02 14:14:46 +08:00
parent 0c0a50ebab
commit 211a634451

10
tree.go
View File

@ -405,7 +405,7 @@ func (n *node) getValue(path string, params *Params, unescape bool) (value nodeV
// level 2 router:123 // level 2 router:123
// level 3 router:def // level 3 router:def
var ( var (
skippedPath = path skippedPath string
latestNode = n // not found `level 2 router` use latestNode latestNode = n // not found `level 2 router` use latestNode
// match '/' count // match '/' count
@ -413,6 +413,10 @@ func (n *node) getValue(path string, params *Params, unescape bool) (value nodeV
// matchNum >= 1: `level (2 or 3 or 4 or ...) router`: Normal handling // matchNum >= 1: `level (2 or 3 or 4 or ...) router`: Normal handling
matchNum int // each match will accumulate matchNum int // each match will accumulate
) )
//if path == "/", no need to look for router
if len(path) == 1 {
matchNum = 1
}
walk: // Outer loop for walking the tree walk: // Outer loop for walking the tree
for { for {
@ -562,7 +566,7 @@ walk: // Outer loop for walking the tree
if path == prefix { if path == prefix {
// level 2 router not found and latestNode.wildChild is ture // level 2 router not found and latestNode.wildChild is ture
if skippedPath != "/" && matchNum < 1 && latestNode.wildChild { if matchNum < 1 && latestNode.wildChild {
n = latestNode.children[len(latestNode.children)-1] n = latestNode.children[len(latestNode.children)-1]
} }
// We should have reached the node containing the handle. // We should have reached the node containing the handle.
@ -594,7 +598,7 @@ walk: // Outer loop for walking the tree
return return
} }
if path != "/" && strings.HasSuffix(skippedPath, path) { if path != "/" {
path = skippedPath path = skippedPath
n = latestNode n = latestNode
skippedPath = "" skippedPath = ""