1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

allow whitespace in regex

This commit is contained in:
Jeffrey Reuling (TI) 2018-06-25 14:45:59 +02:00 committed by Vishal Rana
parent 5ac8bedce8
commit 56091a4186
2 changed files with 4 additions and 1 deletions

View File

@ -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
}

View File

@ -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