Skip to content

Commit

Permalink
Fix incorrect parsing of Windows drive letter quirk (#889)
Browse files Browse the repository at this point in the history
* Fixes the parser to correctly parse "file:///C|/hello/world" into "file:///C:/hello/world"
  • Loading branch information
GabrielDertoni committed Dec 12, 2023
1 parent 92f356e commit 19ebc6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 5 additions & 6 deletions url/src/parser.rs
Expand Up @@ -1038,25 +1038,24 @@ impl<'a> Parser<'a> {
&mut self,
input: Input<'i>,
) -> ParseResult<(bool, HostInternal, Input<'i>)> {
let has_host;
let (_, host_str, remaining) = Parser::file_host(input)?;
let (has_host, host_str, remaining) = Parser::file_host(input)?;
if !has_host {
return Ok((false, HostInternal::None, remaining));
}
let host = if host_str.is_empty() {
has_host = false;
HostInternal::None
} else {
match Host::parse(&host_str)? {
Host::Domain(ref d) if d == "localhost" => {
has_host = false;
HostInternal::None
}
host => {
write!(&mut self.serialization, "{}", host).unwrap();
has_host = true;
host.into()
}
}
};
Ok((has_host, host, remaining))
Ok((true, host, remaining))
}

pub fn file_host(input: Input) -> ParseResult<(bool, String, Input)> {
Expand Down
6 changes: 6 additions & 0 deletions url/tests/unit.rs
Expand Up @@ -1306,3 +1306,9 @@ fn issue_864() {
url.set_path("x");
dbg!(&url);
}

#[test]
fn issue_889() {
let u = Url::parse("file:///C|/hello/world").unwrap();
assert_eq!(u.as_str(), "file:///C:/hello/world");
}

0 comments on commit 19ebc6c

Please sign in to comment.