Improve URL Encoding of Path Component #180
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The example at https://uri.thephpleague.com/uri/6.0/rfc3986/#uri-normalization shows how
Uri::createFromString()
can be used to normalize URLs:Unfortunately, the actual output is not the same as the documented output:
http://www.example.com/hello/./wor%20ld?who=f%203#title
http://www.example.com/hello/./wor ld?who=f%203#title
(Note the unencoded whitespace in the path component and the correctly encoded query component of the actual output.)
This is caused by some unwanted escaping in
URI::formatPath()
's regex:uri/src/Uri.php
Line 975 in 1d6a347
(It should read
|
instead of\|
.)This PR corrects that regex and adds a test case.
Unfortunately, that regex change broke another test: one concerning a Windows path syntax I have not encountered before:
C|
instead of the more commonC:
. To fix that test, I've changed howUri::formatFilePath()
works, but, being unfamiliar with the syntax, I'm not sure if I've actually fixed the underlying problem or if I've just done enough to pass the existing tests. (Also, the changes I made there are a bit ugly :)).