rewrite: fix wrong index check in trimPathPrefix (#7812)

This commit is contained in:
alhuda 2026-06-13 01:41:21 +05:30 committed by GitHub
parent 25b3eab6db
commit 52dc6709fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -432,7 +432,7 @@ func trimPathPrefix(escapedPath, prefix string) string {
}
// if we iterated through the entire prefix, we found it, so trim it
if iPath >= len(prefix) {
if iPrefix >= len(prefix) {
return escapedPath[iPath:]
}

View file

@ -267,6 +267,12 @@ func TestRewrite(t *testing.T) {
input: newRequest(t, "GET", "/foo/prefix/bar"),
expect: newRequest(t, "GET", "/foo/prefix/bar"),
},
{
// shorter (percent-encoded) path that is not the prefix must be left alone
rule: Rewrite{StripPathPrefix: "/aaaaaa"},
input: newRequest(t, "GET", "/%61%61"),
expect: newRequest(t, "GET", "/%61%61"),
},
{
rule: Rewrite{StripPathPrefix: "//prefix"},
// scheme and host needed for URL parser to succeed in setting up test