Collapse all leading slashes for special relative URLs#1136
Open
MerlijnW70 wants to merge 1 commit into
Open
Conversation
When resolving a relative reference against a special base URL (http,
https, ws, wss, ftp), the WHATWG URL standard's "special authority
ignore slashes state" skips *all* leading slashes and backslashes before
the authority. `parse_relative` only stripped the initial `//` and then
parsed the remainder as the authority, so an input such as `///test`
resolved to an authority of `/test` whose leading slash produced an empty
host and an `EmptyHost` error.
Browsers, Node and Bun all resolve `new URL("///test", "http://example.org/")`
to `http://test/`. Branch on `scheme_type.is_special()`: special URLs now
consume every leading slash/backslash (`remaining`) before the authority,
while non-special URLs keep treating only the first `//` as the authority
delimiter and the rest as path.
Drops seven `///`-prefixed http cases from the WPT expected-failures list;
they now parse to the spec-mandated result.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1136 +/- ##
=======================================
Coverage ? 86.74%
=======================================
Files ? 26
Lines ? 5267
Branches ? 0
=======================================
Hits ? 4569
Misses ? 698
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Member
|
It seems that this issue in Deno is attracting many duplicate LLM-generated pull requests. |
Member
|
If this is LLM generated we cannot accept it. https://book.servo.org/contributing/getting-started.html#ai-contributions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Special-scheme URLs with multiple leading slashes (e.g.
///test) were parsedincorrectly and failed with
EmptyHost. Resolvingnew URL("///test", "http://example.org/")returned an error instead of
http://test/, disagreeing with Chrome, Firefox,Node and Bun.
Fix
When resolving a relative reference against a special base URL (
http,https,ws,wss,ftp), the WHATWG URL standard's special authority ignore slashesstate skips all leading slashes and backslashes before the authority.
parse_relativepreviously stripped only the initial//and parsed theremainder as the authority, so
///testproduced an authority of/testwhoseleading slash yielded an empty host.
The fix branches on
scheme_type.is_special(): a special URL now consistentlyconsumes every leading slash/backslash before the authority, while a non-special
URL keeps treating only the first
//as the authority delimiter and the rest asthe path.
Test
No new fixtures were needed — the upstream WPT data in
url/tests/urltestdata.jsonalready encodes the spec-mandated results. These seven
///-prefixed cases (basehttp://example.org/) were removed fromurl/tests/expected_failures.txtand nowpass:
///testhttp://test////\//\//testhttp://test////example.org/pathhttp://example.org/path///example.org/../pathhttp://example.org/path///example.org/../../http://example.org////example.org/../path/../../http://example.org////example.org/../path/../../pathhttp://example.org/pathThe full
url_wptconformance suite passes with no other regressions (the harnessalso flags "unexpected success", confirming these cases genuinely flipped from
failing to passing).
Reference
This is also the upstream cause of downstream issues such as
denoland/deno#35172, since Deno
parses URLs through this crate.