diff options
author | go-d <37667595+go-d@users.noreply.github.com> | 2021-01-11 17:18:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 09:18:53 -0700 |
commit | 88a38bd00d386457aec71696a386449d3bcf8990 (patch) | |
tree | 12df326ddc9282279b5b7be118dee158c38902b3 /modules/caddyhttp/rewrite/rewrite_test.go | |
parent | 4f64105fbb9b315e8faf7a15144fe27e780d5384 (diff) |
rewrite: Use RawPath instead of Path (fix #3596) (#3918)
Prevent information loss, i.e. the encoded form that was sent by the
client, when using URL strip/replace.
Diffstat (limited to 'modules/caddyhttp/rewrite/rewrite_test.go')
-rw-r--r-- | modules/caddyhttp/rewrite/rewrite_test.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/caddyhttp/rewrite/rewrite_test.go b/modules/caddyhttp/rewrite/rewrite_test.go index fb4931b..9329a04 100644 --- a/modules/caddyhttp/rewrite/rewrite_test.go +++ b/modules/caddyhttp/rewrite/rewrite_test.go @@ -201,6 +201,11 @@ func TestRewrite(t *testing.T) { }, { rule: Rewrite{StripPathPrefix: "/prefix"}, + input: newRequest(t, "GET", "/prefix/foo%2Fbar"), + expect: newRequest(t, "GET", "/foo%2Fbar"), + }, + { + rule: Rewrite{StripPathPrefix: "/prefix"}, input: newRequest(t, "GET", "/foo/prefix/bar"), expect: newRequest(t, "GET", "/foo/prefix/bar"), }, @@ -216,6 +221,11 @@ func TestRewrite(t *testing.T) { expect: newRequest(t, "GET", "/foo/bar/"), }, { + rule: Rewrite{StripPathSuffix: "suffix"}, + input: newRequest(t, "GET", "/foo%2Fbar/suffix"), + expect: newRequest(t, "GET", "/foo%2Fbar/"), + }, + { rule: Rewrite{StripPathSuffix: "/suffix"}, input: newRequest(t, "GET", "/foo/suffix/bar"), expect: newRequest(t, "GET", "/foo/suffix/bar"), @@ -231,6 +241,11 @@ func TestRewrite(t *testing.T) { input: newRequest(t, "GET", "/foo/findme/bar"), expect: newRequest(t, "GET", "/foo/replaced/bar"), }, + { + rule: Rewrite{URISubstring: []replacer{{Find: "findme", Replace: "replaced"}}}, + input: newRequest(t, "GET", "/foo/findme%2Fbar"), + expect: newRequest(t, "GET", "/foo/replaced%2Fbar"), + }, } { // copy the original input just enough so that we can // compare it after the rewrite to see if it changed |