Skip to content

Commit 3425025

Browse files
Co-authored-by: yuanyuan <yuanyuan@umu.com>
1 parent 829d723 commit 3425025

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tree.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ walk: // Outer loop for walking the tree
435435
return
436436
}
437437

438+
if path == "/" && n.nType == static {
439+
tsr = true
440+
return
441+
}
442+
438443
// No handle found. Check if a handle for this path + a
439444
// trailing slash exists for trailing slash recommendation
440445
for i, c := range []byte(n.indices) {

tree_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,23 @@ func TestTreeWildcardConflictEx(t *testing.T) {
699699
}
700700
}
701701
}
702+
703+
func TestRedirectTrailingSlash(t *testing.T) {
704+
var data = []struct {
705+
path string
706+
}{
707+
{"/hello/:name"},
708+
{"/hello/:name/123"},
709+
{"/hello/:name/234"},
710+
}
711+
712+
node := &node{}
713+
for _, item := range data {
714+
node.addRoute(item.path, fakeHandler("test"))
715+
}
716+
717+
_, _, tsr := node.getValue("/hello/abx/", nil)
718+
if tsr != true {
719+
t.Fatalf("want true, is false")
720+
}
721+
}

0 commit comments

Comments
 (0)