Reject set_host("") on non-special URLs with credentials or a port (#1144) - #1148
Open
youdie006 wants to merge 1 commit into
Open
Reject set_host("") on non-special URLs with credentials or a port (#1144)#1148youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
Url::set_host's empty-host guard only rejected an empty host for special,
non-file schemes. For a non-special scheme, an empty host fell through to
Host::parse_opaque_cow("") and was accepted, even when the URL carried
credentials or a port. The result is a serialization that the crate's own
parser then rejects with EmptyHost - a broken parse/serialize roundtrip
(e.g. `foo://user@host/` set to an empty host yields `foo://user@/`, which
no longer parses; likewise `foo://host:1/` -> `foo://:1/`).
Mirror the parser, which is the oracle: it rejects `foo://user@/` and
`foo://:1/` but accepts `foo:///`. The guard now also rejects an empty host
on a non-special URL when it has a username, a password, or a port. Empty
host on a non-special scheme with no credentials/port still succeeds and
roundtrips; special/file schemes are unchanged.
Fixes servo#1144.
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.
Fixes #1144.
Root cause
Url::set_host's empty-host guard only rejected an empty host for special, non-fileschemes. For a non-special scheme, an emptyhostfell through toHost::parse_opaque_cow("")and was accepted, even when the URL carried credentials or a port. The result is a serialization that the crate's own parser then rejects withEmptyHost-- a broken parse/serialize roundtrip:The port case (
foo://host:1/->foo://:1/) behaved the same way.Fix
Mirror the parser, which is the oracle here: it rejects
foo://user@/andfoo://:1/but acceptsfoo:///(empty host, no credentials, no port). The guard now also rejects an empty host on a non-special URL when it has a username, a password, or a port. Empty host on a non-special scheme with no credentials/port still succeeds and roundtrips (foo://host/path->foo:///path), and special/fileschemes are unchanged.Tests
Added
test_set_empty_host_non_specialcovering the three credentials/port cases (assertingErr(EmptyHost)with the URL left unchanged) and the empty-host-roundtrip case. Verified red-green (the test fails without the guard change). The full test suite including the WHATWG URL (WPT) conformance suite still passes;cargo fmt --checkandcargo clippy -D warningsare clean.Thanks @DRMacIver for the clear report and minimal repro -- nice catch via the hegel fuzzer. Happy to fold in or collaborate on additional tests per your offer.
This change was prepared with AI assistance and reviewed by me before submission.