Skip to content

Commit dc9374f

Browse files
committed
Check for localhost when setting a file host
1 parent 73589cc commit dc9374f

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
@@ -879,8 +879,7 @@ impl<'a> Parser<'a> {
879879
// url is special and c is U+005C (\)
880880
// If @ flag is set and buffer is the empty string, validation error, return failure.
881881
if let (Some(c), _) = remaining.split_first() {
882-
if c == '/' || c == '?' || c == '#'
883-
|| scheme_type.is_special() && c == '\\' {
882+
if c == '/' || c == '?' || c == '#' || scheme_type.is_special() && c == '\\' {
884883
return Err(ParseError::InvalidAuthority);
885884
}
886885
}
@@ -1015,7 +1014,10 @@ impl<'a> Parser<'a> {
10151014

10161015
pub fn get_file_host<'i>(input: Input<'i>) -> ParseResult<(Host<String>, Input)> {
10171016
let (_, host_str, remaining) = Parser::file_host(input)?;
1018-
let host = Host::parse(&host_str)?;
1017+
let host = match Host::parse(&host_str)? {
1018+
Host::Domain(ref d) if d == "localhost" => Host::Domain("".to_string()),
1019+
host => host,
1020+
};
10191021
Ok((host, remaining))
10201022
}
10211023

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)