X Tutup
Skip to content

lib/rest: fix URLPathEscapeAll encoding RFC 3986 unreserved characters#9241

Open
furmandev wants to merge 1 commit intorclone:masterfrom
furmandev:lib/rest-fix-urlpathescapeall-unreserved-chars
Open

lib/rest: fix URLPathEscapeAll encoding RFC 3986 unreserved characters#9241
furmandev wants to merge 1 commit intorclone:masterfrom
furmandev:lib/rest-fix-urlpathescapeall-unreserved-chars

Conversation

@furmandev
Copy link

What is the purpose of this change?

URLPathEscapeAll only passes [A-Za-z0-9/] through unencoded, causing it to percent-encode the RFC 3986 unreserved characters -, ., _, and ~.

Per RFC 3986 §2.3, unreserved characters MUST NOT be percent-encoded, and a URI that unnecessarily encodes them is not equivalent to one that does not. Servers that perform strict path matching without normalising percent-encoded URIs will reject the over-encoded form with a 404.

This fix adds -, ., _, ~ to the set of characters passed through unencoded. Reserved characters (spaces, semicolons, colons, %, ?, #, etc.) continue to be encoded as before.

Before: /files/my-report.pdf/files/my%2Dreport%2Epdf
After: /files/my-report.pdf/files/my-report.pdf

Was the change discussed in an issue or in the forum before?

No.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

URLPathEscapeAll was only passing [A-Za-z0-9/] through unencoded,
causing it to percent-encode RFC 3986 unreserved characters (-, ., _, ~).
Per RFC 3986 §2.3, unreserved characters MUST NOT be percent-encoded, and
a URI that unnecessarily encodes them is not equivalent to one that does not.

Before: /files/my-report.pdf → /files/my%2Dreport%2Epdf
After:  /files/my-report.pdf → /files/my-report.pdf

Servers that perform strict path matching without normalising
percent-encoded characters will reject the over-encoded form, causing
unexpected 404 errors for paths containing dots, hyphens, underscores,
or tildes.
@ncw
Copy link
Member

ncw commented Mar 9, 2026

This seems like a reasonable thing to do.

Was it causing you an actual problem? If so change the commit message to say

lib/rest: fix XYZ server doing BAD stuff

The first line of the commit message goes in the changelog so make it something users would want to read

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup