diff --git a/url/src/parser.rs b/url/src/parser.rs index 7d94d1d71..693c9f12d 100644 --- a/url/src/parser.rs +++ b/url/src/parser.rs @@ -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)> { diff --git a/url/tests/unit.rs b/url/tests/unit.rs index c27f237ba..82ec422d8 100644 --- a/url/tests/unit.rs +++ b/url/tests/unit.rs @@ -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"); +}