mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-30 04:33:48 +08:00
parent
e747a9bb12
commit
013b510352
|
@ -383,8 +383,13 @@ func trimPathPrefix(escapedPath, prefix string) string {
|
|||
iPrefix++
|
||||
}
|
||||
|
||||
// found matching prefix, trim it
|
||||
return escapedPath[iPath:]
|
||||
// if we iterated through the entire prefix, we found it, so trim it
|
||||
if iPath >= len(prefix) {
|
||||
return escapedPath[iPath:]
|
||||
}
|
||||
|
||||
// otherwise we did not find the prefix
|
||||
return escapedPath
|
||||
}
|
||||
|
||||
func reverse(s string) string {
|
||||
|
|
|
@ -225,6 +225,16 @@ func TestRewrite(t *testing.T) {
|
|||
input: newRequest(t, "GET", "/prefix/foo/bar"),
|
||||
expect: newRequest(t, "GET", "/foo/bar"),
|
||||
},
|
||||
{
|
||||
rule: Rewrite{StripPathPrefix: "/prefix"},
|
||||
input: newRequest(t, "GET", "/prefix"),
|
||||
expect: newRequest(t, "GET", ""),
|
||||
},
|
||||
{
|
||||
rule: Rewrite{StripPathPrefix: "/prefix"},
|
||||
input: newRequest(t, "GET", "/"),
|
||||
expect: newRequest(t, "GET", "/"),
|
||||
},
|
||||
{
|
||||
rule: Rewrite{StripPathPrefix: "/prefix"},
|
||||
input: newRequest(t, "GET", "/prefix/foo%2Fbar"),
|
||||
|
|
Loading…
Reference in New Issue
Block a user