Skip to content

Ensure opaque paths always roundtrip #844

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

Merged
merged 2 commits into from
Mar 14, 2025
Merged

Ensure opaque paths always roundtrip #844

merged 2 commits into from
Mar 14, 2025

Conversation

annevk
Copy link
Member

@annevk annevk commented Dec 2, 2024

In fdaa0e5 we tackled a problem whereby removing the fragment or query from a URL with an opaque path through the API would not make the URL roundtrip due to the opaque path being able to end in non-percent-encoded spaces.

However, this failed to address other ways of serializing the URL. As such this is a new approach whereby opaque paths simply cannot end with non-percent-encoded spaces. Enforcing this in the URL parser allows us to completely revert the aforementioned commit, greatly simplifying the API implementation.

Fixes #784.


(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@annevk
Copy link
Member Author

annevk commented Feb 24, 2025

@karwa @hayatoito @valenting what do you think? We should be able to make test changes again so would be great to hear what the interest in this change is.

@valenting
Copy link
Collaborator

I'm supportive of this change. It's a nice simplification, and slightly better than having to strip spaces from the path when clearing the search or hash. I plan to be making these changes in Firefox once WPT tests are available.

@karwa
Copy link
Contributor

karwa commented Mar 6, 2025

(thanks for this, and apologies for the long delay!)

+1. This is a lot more predictable for users.

I hope it is web-compatible. I understand that there are use-cases which unfortunately require that unescaped spaces are preserved (e.g. javascript: URLs), but I can't imagine that trailing spaces are important to any of them.

@annevk
Copy link
Member Author

annevk commented Mar 6, 2025

Unfortunately I think I need a bit more assurance that everyone is still willing to try this after encountering some unexpected data: and javascript: URLs in tests: #784 (comment).

@annevk annevk added the do not merge yet Pull request must not be merged per rationale in comment label Mar 6, 2025
annevk added a commit to web-platform-tests/wpt that referenced this pull request Mar 12, 2025
In fdaa0e5 we tackled a problem whereby removing the fragment or query from a URL with an opaque path through the API would not make the URL roundtrip due to the opaque path being able to end in non-percent-encoded spaces.

However, this failed to address other ways of serializing the URL. As such this is a new approach whereby opaque paths simply cannot end with non-percent-encoded spaces. Enforcing this in the URL parser allows us to completely revert the aforementioned commit, greatly simplifying the API implementation.

Fixes #784.
@annevk annevk removed the do not merge yet Pull request must not be merged per rationale in comment label Mar 12, 2025
@domenic
Copy link
Member

domenic commented Mar 13, 2025

I guess this also obsoletes #785.

annevk added a commit to web-platform-tests/wpt that referenced this pull request Mar 14, 2025
annevk added a commit to web-platform-tests/wpt that referenced this pull request Mar 14, 2025
@annevk annevk merged commit 6c78200 into main Mar 14, 2025
2 checks passed
@annevk annevk deleted the opaque-paths branch March 14, 2025 00:47
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request Mar 14, 2025
https://bugs.webkit.org/show_bug.cgi?id=289160
rdar://146848690

Reviewed by Alex Christensen.

Instead of attempting to account for opaque paths sometimes ending in
spaces in the API implementation and failing because that did not
account for serialization, this new approach always percent-encodes the
final space of the path. This is thought to be the least invasive
change that is hopefully web-compatible. This is standardized here:
whatwg/url#844

Test changes are upstreamed here:
web-platform-tests/wpt#51129

* LayoutTests/fast/events/popup-blocked-from-unique-frame-via-window-open-named-sibling-frame-expected.txt:
* LayoutTests/http/tests/security/no-popup-from-sandbox-top-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element-origin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element-origin-xhtml-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/resources/setters_tests.json:
* LayoutTests/imported/w3c/web-platform-tests/url/resources/urltestdata.json:
* LayoutTests/imported/w3c/web-platform-tests/url/url-constructor.any.worker_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-constructor.any_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-origin.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-origin.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-setters-a-area.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-setters.any.worker_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-setters.any_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-delete.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-delete.any.js:
(test):
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-delete.any.worker-expected.txt:
* Source/WTF/wtf/URL.cpp:
(WTF::URL::removeFragmentIdentifier):
(WTF::URL::removeQueryAndFragmentIdentifier):
(WTF::URL::setQuery):
(WTF::URL::maybeTrimTrailingSpacesFromOpaquePath): Deleted.
* Source/WTF/wtf/URL.h:
* Source/WTF/wtf/URLParser.cpp:
(WTF::URLParser::parse):

Canonical link: https://commits.webkit.org/292146@main
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Mar 18, 2025
…from opaque paths, a=testonly

Automatic update from web-platform-tests
URL: ensure opaque paths always roundtrip

For whatwg/url#844.
--

wpt-commits: 048018b5af85f8d47b8a704b48cf6f9c0a461876
wpt-pr: 51129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

URL serialiser does not produce idempotent strings if an opaque path has a trailing space and "exclude fragment" is true
5 participants