set_host("localhost") on file:// URL produces non-roundtripping serialization
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 406
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Calling set_host(Some("localhost")) on a file:/// URL produces file://localhost/..., but re-parsing that serialization strips localhost per the WHATWG URL spec (which normalizes file://localhost/ to file:///). This means the URL produced by set_host does not roundtrip through Url::parse.
Reproduction
use url::Url;
fn main() {
let mut url = Url::parse("file:///tmp/test").unwrap();
url.set_host(Some("localhost")).unwrap();
let modified = url.as_str().to_string();
println!("After set_host: {:?}", modified);
// After set_host: "file://localhost/tmp/test"
let reparsed = Url::parse(&modified).unwrap();
println!("Reparsed: {:?}", reparsed.as_str());
// Reparsed: "file:///tmp/test"
assert_eq!(modified, reparsed.as_str()); // FAILS
}
Analysis
Per the WHATWG URL standard, file://localhost/ is normalized to file:/// during parsing. The set_host method should apply the same normalization — when setting the host to "localhost" on a file:// URL, it should either:
- Normalize it away (set host to empty/None), or
- Serialize it without
localhostso the output roundtrips
Currently set_host stores localhost literally, producing a serialization that the parser will normalize differently on re-parse.
Found by
This bug was found by fuzzing with the fuzz_url_setters target (see #1100).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing set_host and Url::parse for file:// URLs, then inspect the fuzz_url_setters target mentioned in the issue. Reproduce the localhost case and compare setter serialization with parser normalization. Done means the behavior follows the WHATWG rule and the serialized URL roundtrips consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100