mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
revert and update rules
This commit is contained in:
parent
0c0a50ebab
commit
211a634451
10
tree.go
10
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 = ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user