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