Skip to content

Commit 7dda791

Browse files
Fix incorrect parsing of Windows drive letter quirk (#889)
* Fixes the parser to correctly parse "file:///C|/hello/world" into "file:///C:/hello/world"
1 parent 92f356e commit 7dda791

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

url/src/parser.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,25 +1038,24 @@ impl<'a> Parser<'a> {
10381038
&mut self,
10391039
input: Input<'i>,
10401040
) -> ParseResult<(bool, HostInternal, Input<'i>)> {
1041-
let has_host;
1042-
let (_, host_str, remaining) = Parser::file_host(input)?;
1041+
let (has_host, host_str, remaining) = Parser::file_host(input)?;
1042+
if !has_host {
1043+
return Ok((false, HostInternal::None, remaining));
1044+
}
10431045
let host = if host_str.is_empty() {
1044-
has_host = false;
10451046
HostInternal::None
10461047
} else {
10471048
match Host::parse(&host_str)? {
10481049
Host::Domain(ref d) if d == "localhost" => {
1049-
has_host = false;
10501050
HostInternal::None
10511051
}
10521052
host => {
10531053
write!(&mut self.serialization, "{}", host).unwrap();
1054-
has_host = true;
10551054
host.into()
10561055
}
10571056
}
10581057
};
1059-
Ok((has_host, host, remaining))
1058+
Ok((true, host, remaining))
10601059
}
10611060

10621061
pub fn file_host(input: Input) -> ParseResult<(bool, String, Input)> {

url/tests/unit.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,3 +1306,9 @@ fn issue_864() {
13061306
url.set_path("x");
13071307
dbg!(&url);
13081308
}
1309+
1310+
#[test]
1311+
fn issue_889() {
1312+
let u = Url::parse("file:///C|/hello/world").unwrap();
1313+
assert_eq!(u.as_str(), "file:///C:/hello/world");
1314+
}

0 commit comments

Comments
 (0)