Skip to content

Commit dba0e4d

Browse files
committed
Handle file URLs with host when path starts with Windows drive letter
1 parent edee129 commit dba0e4d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/parser.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,9 @@ impl<'a> Parser<'a> {
476476
self.serialization.push_str("file://");
477477
let scheme_end = "file".len() as u32;
478478
let host_start = "file://".len() as u32;
479-
let (path_start, host, remaining) =
479+
let (path_start, mut host, remaining) =
480480
self.parse_file_host(input_after_next_char)?;
481-
let host_end = to_u32(self.serialization.len())?;
481+
let mut host_end = to_u32(self.serialization.len())?;
482482
let mut has_host = !matches!(host, HostInternal::None);
483483
let remaining = if path_start {
484484
self.parse_path_start(SchemeType::File, &mut has_host, remaining)
@@ -487,7 +487,13 @@ impl<'a> Parser<'a> {
487487
self.serialization.push('/');
488488
self.parse_path(SchemeType::File, &mut has_host, path_start, remaining)
489489
};
490-
// FIXME: deal with has_host
490+
// For file URLs that have a host and whose path starts
491+
// with the windows drive letter we just remove the host.
492+
if !has_host {
493+
self.serialization.drain(host_start as usize..host_end as usize);
494+
host_end = host_start;
495+
host = HostInternal::None;
496+
}
491497
let (query_start, fragment_start) =
492498
self.parse_query_and_fragment(scheme_end, remaining)?;
493499
Ok(Url {

0 commit comments

Comments
 (0)