There was an error while loading. Please reload this page.
1 parent 84da507 commit 68e8bceCopy full SHA for 68e8bce
middleware/rewrite.go
@@ -59,11 +59,7 @@ func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFunc {
59
for k, v := range config.Rules {
60
k = regexp.QuoteMeta(k)
61
k = strings.Replace(k, `\*`, "(.*)", -1)
62
-k = strings.Replace(k, `\^`, "^", -1)
63
k = k + "$"
64
-if strings.HasPrefix(k, "/") {
65
-k = "^" + k
66
-}
67
config.rulesRegex[regexp.MustCompile(k)] = v
68
}
69
middleware/rewrite_test.go
@@ -18,10 +18,6 @@ func TestRewrite(t *testing.T) {
18
"/api/*": "/$1",
19
"/js/*": "/public/javascripts/$1",
20
"/users/*/orders/*": "/user/$1/order/$2",
21
-"/foo/*": "/v1/foo/$1",
22
-"/v1/foo/*": "/v1/foo/$1",
23
-"/v2/foo/*": "/v2/foo/$1",
24
-"^/bar/*": "/foobar/$1",
25
},
26
}))
27
req := httptest.NewRequest(http.MethodGet, "/", nil)
@@ -41,18 +37,6 @@ func TestRewrite(t *testing.T) {
41
37
req.URL.Path = "/api/new users"
42
38
e.ServeHTTP(rec, req)
43
39
assert.Equal(t, "/new users", req.URL.Path)
44
-req.URL.Path = "/foo/bar"
45
-e.ServeHTTP(rec, req)
46
-assert.Equal(t, "/v1/foo/bar", req.URL.Path)
47
-req.URL.Path = "/v1/foo/bar"
48
49
50
-req.URL.Path = "/v2/foo/bar"
51
52
-assert.Equal(t, "/v2/foo/bar", req.URL.Path)
53
-req.URL.Path = "/bar/baz"
54
55
-assert.Equal(t, "/foobar/baz", req.URL.Path)
56
40
57
58
// Issue #1086
0 commit comments