Skip to content

Commit

Permalink
fix: #846 (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
AthfanFasee authored Oct 19, 2023
1 parent 355dd04 commit f4ab9b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit f4ab9b1

Please sign in to comment.