Skip to content

Commit 52dc670

Browse files
authored
rewrite: fix wrong index check in trimPathPrefix (#7812)
1 parent 25b3eab commit 52dc670

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

modules/caddyhttp/rewrite/rewrite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func trimPathPrefix(escapedPath, prefix string) string {
432432
}
433433

434434
// if we iterated through the entire prefix, we found it, so trim it
435-
if iPath >= len(prefix) {
435+
if iPrefix >= len(prefix) {
436436
return escapedPath[iPath:]
437437
}
438438

modules/caddyhttp/rewrite/rewrite_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ func TestRewrite(t *testing.T) {
267267
input: newRequest(t, "GET", "/foo/prefix/bar"),
268268
expect: newRequest(t, "GET", "/foo/prefix/bar"),
269269
},
270+
{
271+
// shorter (percent-encoded) path that is not the prefix must be left alone
272+
rule: Rewrite{StripPathPrefix: "/aaaaaa"},
273+
input: newRequest(t, "GET", "/%61%61"),
274+
expect: newRequest(t, "GET", "/%61%61"),
275+
},
270276
{
271277
rule: Rewrite{StripPathPrefix: "//prefix"},
272278
// scheme and host needed for URL parser to succeed in setting up test

0 commit comments

Comments
 (0)