-
Notifications
You must be signed in to change notification settings - Fork 22.9k
Document trailing space handling in opaque URL paths #41127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document trailing space handling in opaque URL paths #41127
Conversation
a8e8930
to
f153278
Compare
Preview URLs (comment last updated: 2025-09-15 13:57:44) |
For non-hierarchical schemes, the pathname is known as an _opaque path_ (meaning, the URL parser does not try to split it into a list of segments). In this case, an empty path results in the `pathname` property being the empty string. Trailing spaces in opaque paths are stripped during initial parsing if the `hash` and `search` are both empty; otherwise, they are percent-encoded as `%20` even when `hash` and `search` are later set to empty strings. | ||
|
||
> [!NOTE] | ||
> Percent-encoding trailing spaces in opaque paths is not widely implemented. Some browsers implement the old behavior of stripping trailing spaces from `pathname` whenever the `hash` and `search` properties are both empty strings. In these browsers, setting `hash` or `search` may change the `pathname` as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those setters with side effects have also only been in place for a relatively short period so older browsers do not even have that and instead end up with a trailing space in the path that would disappear after a serialize-then-parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably this "even older behavior" is a bug, and has been gone for 2 years already, so I opted to not include it because it makes things even more complicated—it's fine to only document the status quo and not history, and I only included this note because of current divergence, not because of historical change. I've filed a BCD issue to get both behaviors' versions recorded, so this should be backed by real data soon. Of course if you have some wording suggestion in mind, I would be happy to make it more complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not encoding to %20 is also a bug at this point though. 😊
I've updated with mentioning of the even-older behavior |
Fix #23320. See also mdn/browser-compat-data#27856
cc @annevk to see if this makes sense