From 56091a418657bf36f44fcb061f2e307ed39fc29a Mon Sep 17 00:00:00 2001 From: "Jeffrey Reuling (TI)" Date: Mon, 25 Jun 2018 14:45:59 +0200 Subject: [PATCH] allow whitespace in regex --- middleware/rewrite.go | 2 +- middleware/rewrite_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/middleware/rewrite.go b/middleware/rewrite.go index 60a59bec..e7ddce37 100644 --- a/middleware/rewrite.go +++ b/middleware/rewrite.go @@ -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 } diff --git a/middleware/rewrite_test.go b/middleware/rewrite_test.go index afe0c1d1..03f21ced 100644 --- a/middleware/rewrite_test.go +++ b/middleware/rewrite_test.go @@ -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