Skip to content

Commit

Permalink
allow whitespace in regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Reuling (TI) authored and vishr committed Jun 26, 2018
1 parent 5ac8bed commit 56091a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion middleware/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFunc {

// Initialize
for k, v := range config.Rules {
k = strings.Replace(k, "*", "(\\S*)", -1)
k = strings.Replace(k, "*", "(.*)", -1)
config.rulesRegex[regexp.MustCompile(k)] = v
}

Expand Down
3 changes: 3 additions & 0 deletions middleware/rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func TestRewrite(t *testing.T) {
req.URL.Path = "/users/jack/orders/1"
e.ServeHTTP(rec, req)
assert.Equal(t, "/user/jack/order/1", req.URL.Path)
req.URL.Path = "/api/new users"
e.ServeHTTP(rec, req)
assert.Equal(t, "/new users", req.URL.Path)
}

// Issue #1086
Expand Down

0 comments on commit 56091a4

Please sign in to comment.