Fix file:// URL roundtrip bugs (#1101, #1102) #1103
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
This PR fixes two bugs found through OSS-Fuzz that caused file:// URLs to fail roundtrip tests (parse → serialize → parse).
Fixes #1101 - File URLs with hosts and paths containing multiple slashes were losing their host component during roundtrip
Fixes #1102 -
set_host("localhost")on file:// URLs didn't normalize localhost to empty host like the parser doesChanges
Bug #1101: Path structure preservation
Problem: When parsing file URLs like
file://host//path, the path normalization was stripping all leading slashes, causing the host to be lost on re-parse.Fix: Modified
parse_path()inparser.rsto preserve path structure when a host component is present. Leading slash normalization now only applies to hostless file:// URLs.Example:
Bug #1102: localhost normalization in set_host()
Problem: The URL parser normalizes "localhost" to empty host for file:// URLs per WHATWG spec, but
set_host()wasn't applying the same normalization, causing asymmetric behavior.Fix: Modified
set_host()inlib.rsto normalize "localhost" toNonefor file:// URLs, matching the parser's behavior.Example:
Impact
file://spider///file://monkey/with pathname set to\\\\file:///unicornwith pathname set to//\\/file:///unicornwith pathname set to//monkey/..//Testing
Added comprehensive test suite in
url/tests/roundtrip_bugs.rsthat reproduces both bugs and verifies the fixes.WHATWG Spec Compliance
Both fixes align with the WHATWG URL Standard:
Found while integrating rust-url with OSS-Fuzz for continuous fuzzing.