From 211a63445181f085e95200f28bae8476211ade26 Mon Sep 17 00:00:00 2001 From: qm012 Date: Fri, 2 Jul 2021 14:14:46 +0800 Subject: [PATCH] revert and update rules --- tree.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tree.go b/tree.go index cf08adc0..42c843d5 100644 --- a/tree.go +++ b/tree.go @@ -405,7 +405,7 @@ func (n *node) getValue(path string, params *Params, unescape bool) (value nodeV // level 2 router:123 // level 3 router:def var ( - skippedPath = path + skippedPath string latestNode = n // not found `level 2 router` use latestNode // 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 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 for { @@ -562,7 +566,7 @@ walk: // Outer loop for walking the tree if path == prefix { // 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] } // We should have reached the node containing the handle. @@ -594,7 +598,7 @@ walk: // Outer loop for walking the tree return } - if path != "/" && strings.HasSuffix(skippedPath, path) { + if path != "/" { path = skippedPath n = latestNode skippedPath = ""