File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,8 @@ func countSections(path string) uint16 {
107107type nodeType uint8
108108
109109const (
110- root nodeType = iota + 1
110+ static nodeType = iota
111+ root
111112 param
112113 catchAll
113114)
@@ -173,6 +174,7 @@ walk:
173174 child := node {
174175 path : n .path [i :],
175176 wildChild : n .wildChild ,
177+ nType : static ,
176178 indices : n .indices ,
177179 children : n .children ,
178180 handlers : n .handlers ,
@@ -604,6 +606,11 @@ walk: // Outer loop for walking the tree
604606 return
605607 }
606608
609+ if path == "/" && n .nType == static {
610+ value .tsr = true
611+ return
612+ }
613+
607614 // No handle found. Check if a handle for this path + a
608615 // trailing slash exists for trailing slash recommendation
609616 for i , c := range []byte (n .indices ) {
Original file line number Diff line number Diff line change @@ -684,6 +684,26 @@ func TestTreeRootTrailingSlashRedirect(t *testing.T) {
684684 }
685685}
686686
687+ func TestRedirectTrailingSlash (t * testing.T ) {
688+ var data = []struct {
689+ path string
690+ }{
691+ {"/hello/:name" },
692+ {"/hello/:name/123" },
693+ {"/hello/:name/234" },
694+ }
695+
696+ node := & node {}
697+ for _ , item := range data {
698+ node .addRoute (item .path , fakeHandler ("test" ))
699+ }
700+
701+ value := node .getValue ("/hello/abx/" , nil , getSkippedNodes (), false )
702+ if value .tsr != true {
703+ t .Fatalf ("want true, is false" )
704+ }
705+ }
706+
687707func TestTreeFindCaseInsensitivePath (t * testing.T ) {
688708 tree := & node {}
689709
You can’t perform that action at this time.
0 commit comments