Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect parsing of Windows drive letter quirk (#889) #890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
}