fix: parse relative URLs with multiple leading slashes for special schemes#1137
Closed
ZachDreamZ wants to merge 1 commit into
Closed
fix: parse relative URLs with multiple leading slashes for special schemes#1137ZachDreamZ wants to merge 1 commit into
ZachDreamZ wants to merge 1 commit into
Conversation
…hemes
When a relative URL starts with more than two slashes (e.g. ///test)
and the base has a special scheme (http, https, ws, wss, ftp), the
parser should consume all leading slashes before parsing the authority,
matching the URL spec's special authority slashes state.
Previously, split_prefix("//") only consumed exactly two slashes,
leaving the remaining slash to be parsed as part of the authority,
which caused an empty host error for inputs like ///test with base
http://example.org/.
This fix adds a check for special schemes before the split_prefix
call, routing directly to after_double_slash which handles the
remaining input correctly.
Fixes URL parsing for:
new URL('///test', 'http://example.org/') -> http://test/
new URL('///example.org/path', 'http://example.org/') -> http://example.org/path
Removed 7 entries from expected_failures.txt that now pass correctly.
Member
|
Duplicate of #1136. |
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.
What's wrong
When a relative URL starts with more than two slashes (e.g.
///test) and the base URL has a special scheme (http,https,ws,wss,ftp), the parser throws an error instead of correctly parsing it.This matches Chrome, Firefox, Node, and Bun behavior. The URL spec's special authority slashes state says all leading slashes should be consumed before parsing the authority.
What this does
In
parse_relative, when we have a base URL with a special scheme, we now route directly toafter_double_slashwith the remaining input, which correctly handles multiple leading slashes. The existingsplit_prefix("//")path is kept for non-special schemes.Also removed 7 entries from
expected_failures.txtthat now pass correctly:///testagainsthttp://example.org////example.org/pathagainsthttp://example.org/Test plan
Context
This was previously reported as denoland/deno#35172 where
new URL("///test", "http://example.org")throws in Deno but works in all other browsers and runtimes.