Skip to content

Commit 1b61ad4

Browse files
committed
Check for localhost when setting a file host
1 parent 72142a7 commit 1b61ad4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ impl<'a> Parser<'a> {
897897
// url is special and c is U+005C (\)
898898
// If @ flag is set and buffer is the empty string, validation error, return failure.
899899
if let (Some(c), _) = remaining.split_first() {
900-
if c == '/' || c == '?' || c == '#'
901-
|| scheme_type.is_special() && c == '\\' {
900+
if c == '/' || c == '?' || c == '#' || scheme_type.is_special() && c == '\\' {
902901
return Err(ParseError::InvalidAuthority);
903902
}
904903
}
@@ -1033,7 +1032,10 @@ impl<'a> Parser<'a> {
10331032

10341033
pub fn get_file_host<'i>(input: Input<'i>) -> ParseResult<(Host<String>, Input)> {
10351034
let (_, host_str, remaining) = Parser::file_host(input)?;
1036-
let host = Host::parse(&host_str)?;
1035+
let host = match Host::parse(&host_str)? {
1036+
Host::Domain(ref d) if d == "localhost" => Host::Domain("".to_string()),
1037+
host => host,
1038+
};
10371039
Ok((host, remaining))
10381040
}
10391041

src/quirks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
177177
if let Ok((host, _remaining)) = result {
178178
if let Host::Domain(h) = &host {
179179
if h.is_empty() {
180-
// Empty host on special url
181-
if SchemeType::from(url.scheme()).is_special()
180+
// Empty host on special not file url
181+
if SchemeType::from(url.scheme()) == SchemeType::SpecialNotFile
182182
// Port with an empty host
183183
||!port(&url).is_empty()
184184
// Empty host with includes credentials

0 commit comments

Comments
 (0)