Skip to content

Commit

Permalink
Revert "Fixes the uses of caret(^) in rewrite regex"
Browse files Browse the repository at this point in the history
This reverts commit 1f51469.
  • Loading branch information
choyri committed Jul 24, 2020
1 parent 84da507 commit 68e8bce
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 20 deletions.
4 changes: 0 additions & 4 deletions middleware/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFunc {
for k, v := range config.Rules {
k = regexp.QuoteMeta(k)
k = strings.Replace(k, `\*`, "(.*)", -1)
k = strings.Replace(k, `\^`, "^", -1)
k = k + "$"
if strings.HasPrefix(k, "/") {
k = "^" + k
}
config.rulesRegex[regexp.MustCompile(k)] = v
}

Expand Down
16 changes: 0 additions & 16 deletions middleware/rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ func TestRewrite(t *testing.T) {
"/api/*": "/$1",
"/js/*": "/public/javascripts/$1",
"/users/*/orders/*": "/user/$1/order/$2",
"/foo/*": "/v1/foo/$1",
"/v1/foo/*": "/v1/foo/$1",
"/v2/foo/*": "/v2/foo/$1",
"^/bar/*": "/foobar/$1",
},
}))
req := httptest.NewRequest(http.MethodGet, "/", nil)
Expand All @@ -41,18 +37,6 @@ func TestRewrite(t *testing.T) {
req.URL.Path = "/api/new users"
e.ServeHTTP(rec, req)
assert.Equal(t, "/new users", req.URL.Path)
req.URL.Path = "/foo/bar"
e.ServeHTTP(rec, req)
assert.Equal(t, "/v1/foo/bar", req.URL.Path)
req.URL.Path = "/v1/foo/bar"
e.ServeHTTP(rec, req)
assert.Equal(t, "/v1/foo/bar", req.URL.Path)
req.URL.Path = "/v2/foo/bar"
e.ServeHTTP(rec, req)
assert.Equal(t, "/v2/foo/bar", req.URL.Path)
req.URL.Path = "/bar/baz"
e.ServeHTTP(rec, req)
assert.Equal(t, "/foobar/baz", req.URL.Path)
}

// Issue #1086
Expand Down

0 comments on commit 68e8bce

Please sign in to comment.