@@ -448,27 +448,26 @@ walk: // Outer loop for walking the tree
448
448
continue walk
449
449
}
450
450
}
451
- // If the path at the end of the loop is not equal to '/' and the current node has no child nodes
452
- // the current node needs to roll back to last vaild skippedNode
453
-
454
- if path != "/" && ! n .wildChild {
455
- for l := len (* skippedNodes ); l > 0 ; {
456
- skippedNode := (* skippedNodes )[l - 1 ]
457
- * skippedNodes = (* skippedNodes )[:l - 1 ]
458
- if strings .HasSuffix (skippedNode .path , path ) {
459
- path = skippedNode .path
460
- n = skippedNode .node
461
- if value .params != nil {
462
- * value .params = (* value .params )[:skippedNode .paramsCount ]
451
+
452
+ if ! n .wildChild {
453
+ // If the path at the end of the loop is not equal to '/' and the current node has no child nodes
454
+ // the current node needs to roll back to last vaild skippedNode
455
+ if path != "/" {
456
+ for l := len (* skippedNodes ); l > 0 ; {
457
+ skippedNode := (* skippedNodes )[l - 1 ]
458
+ * skippedNodes = (* skippedNodes )[:l - 1 ]
459
+ if strings .HasSuffix (skippedNode .path , path ) {
460
+ path = skippedNode .path
461
+ n = skippedNode .node
462
+ if value .params != nil {
463
+ * value .params = (* value .params )[:skippedNode .paramsCount ]
464
+ }
465
+ globalParamsCount = skippedNode .paramsCount
466
+ continue walk
463
467
}
464
- globalParamsCount = skippedNode .paramsCount
465
- continue walk
466
468
}
467
469
}
468
- }
469
470
470
- // If there is no wildcard pattern, recommend a redirection
471
- if ! n .wildChild {
472
471
// Nothing found.
473
472
// We can recommend to redirect to the same URL without a
474
473
// trailing slash if a leaf exists for that path.
@@ -615,8 +614,14 @@ walk: // Outer loop for walking the tree
615
614
return
616
615
}
617
616
618
- // roll back to last vaild skippedNode
619
- if path != "/" {
617
+ // Nothing found. We can recommend to redirect to the same URL with an
618
+ // extra trailing slash if a leaf exists for that path
619
+ value .tsr = path == "/" ||
620
+ (len (prefix ) == len (path )+ 1 && prefix [len (path )] == '/' &&
621
+ path == prefix [:len (prefix )- 1 ] && n .handlers != nil )
622
+
623
+ // roll back to last valid skippedNode
624
+ if ! value .tsr && path != "/" {
620
625
for l := len (* skippedNodes ); l > 0 ; {
621
626
skippedNode := (* skippedNodes )[l - 1 ]
622
627
* skippedNodes = (* skippedNodes )[:l - 1 ]
@@ -632,11 +637,6 @@ walk: // Outer loop for walking the tree
632
637
}
633
638
}
634
639
635
- // Nothing found. We can recommend to redirect to the same URL with an
636
- // extra trailing slash if a leaf exists for that path
637
- value .tsr = path == "/" ||
638
- (len (prefix ) == len (path )+ 1 && prefix [len (path )] == '/' &&
639
- path == prefix [:len (prefix )- 1 ] && n .handlers != nil )
640
640
return
641
641
}
642
642
}
0 commit comments