diff --git a/context.go b/context.go index 0eda1a24..6aaee8bd 100644 --- a/context.go +++ b/context.go @@ -123,8 +123,10 @@ func (x *Context) URLParam(key string) string { func (x *Context) RoutePattern() string { routePattern := strings.Join(x.RoutePatterns, "") routePattern = replaceWildcards(routePattern) - routePattern = strings.TrimSuffix(routePattern, "//") - routePattern = strings.TrimSuffix(routePattern, "/") + if routePattern != "/" { + routePattern = strings.TrimSuffix(routePattern, "//") + routePattern = strings.TrimSuffix(routePattern, "/") + } return routePattern } diff --git a/context_test.go b/context_test.go index 83795209..9a254ab8 100644 --- a/context_test.go +++ b/context_test.go @@ -75,4 +75,11 @@ func TestRoutePattern(t *testing.T) { if p := x.RoutePattern(); p != "/v1/resources/*special_path/with_asterisks*/{resource_id}" { t.Fatal("unexpected route pattern: " + p) } + + // Testing for the root route pattern + x.RoutePatterns = []string{"/"} + // It should just return "/" as the pattern + if p := x.RoutePattern(); p != "/" { + t.Fatal("unexpected route pattern for root: " + p) + } }