Skip to content

Conversation

Josh-Cena
Copy link
Member

Fix #23320. See also mdn/browser-compat-data#27856

cc @annevk to see if this makes sense

@Josh-Cena Josh-Cena requested a review from a team as a code owner September 15, 2025 03:53
@Josh-Cena Josh-Cena requested review from sideshowbarker and removed request for a team September 15, 2025 03:53
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Sep 15, 2025
@Josh-Cena Josh-Cena force-pushed the opaque-path-trailing-sapce branch from a8e8930 to f153278 Compare September 15, 2025 03:54
Copy link
Contributor

github-actions bot commented Sep 15, 2025

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.
Copy link
Contributor

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.

Copy link
Member Author

@Josh-Cena Josh-Cena Sep 15, 2025

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

Copy link
Contributor

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. 😊

@Josh-Cena
Copy link
Member Author

I've updated with mentioning of the even-older behavior

@sideshowbarker sideshowbarker merged commit 42cbee2 into mdn:main Sep 19, 2025
8 checks passed
@Josh-Cena Josh-Cena deleted the opaque-path-trailing-sapce branch September 19, 2025 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL standard update: opaque paths cannot have trailing space
3 participants