Fix TSR for empty path Resulted in a panic before. Fixes #45
diff --git a/router.go b/router.go index a6be43c..7716dc7 100644 --- a/router.go +++ b/router.go
@@ -289,7 +289,7 @@ } if tsr && r.RedirectTrailingSlash { - if path[len(path)-1] == '/' { + if len(path) > 1 && path[len(path)-1] == '/' { req.URL.Path = path[:len(path)-1] } else { req.URL.Path = path + "/"
diff --git a/router_test.go b/router_test.go index 08dab29..19aeb39 100644 --- a/router_test.go +++ b/router_test.go
@@ -171,6 +171,7 @@ router := New() router.GET("/path", handlerFunc) router.GET("/dir/", handlerFunc) + router.GET("/", handlerFunc) testRoutes := []struct { route string @@ -179,6 +180,7 @@ }{ {"/path/", 301, "map[Location:[/path]]"}, // TSR -/ {"/dir", 301, "map[Location:[/dir/]]"}, // TSR +/ + {"/dir", 301, "map[Location:[/dir/]]"}, // TSR +/ {"/PATH", 301, "map[Location:[/path]]"}, // Fixed Case {"/DIR/", 301, "map[Location:[/dir/]]"}, // Fixed Case {"/PATH/", 301, "map[Location:[/path]]"}, // Fixed Case -/