From f4ab9b1f050bdcf14bd096399e8bd57363406514 Mon Sep 17 00:00:00 2001 From: Athfan Fasee Date: Thu, 19 Oct 2023 05:30:59 +0530 Subject: [PATCH] fix: #846 (#847) --- context.go | 6 ++++-- context_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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) + } }