Skip to content

Commit c6284a2

Browse files
author
bors-servo
authored
Auto merge of #410 - valenting:win-file-letter, r=SimonSapin
Properly file URLs when the path starts with a windows drive letter This change imports tests from web-platform-tests/wpt@634175d corresponding to URL change whatwg/url#272 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/410) <!-- Reviewable:end -->
2 parents edee129 + cd6a779 commit c6284a2

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-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 {

tests/urltestdata.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5342,6 +5342,49 @@
53425342
"search": "",
53435343
"hash": ""
53445344
},
5345+
"# Windows drive letter quirk with not empty host",
5346+
{
5347+
"input": "file://example.net/C:/",
5348+
"base": "about:blank",
5349+
"href": "file:///C:/",
5350+
"protocol": "file:",
5351+
"username": "",
5352+
"password": "",
5353+
"host": "",
5354+
"hostname": "",
5355+
"port": "",
5356+
"pathname": "/C:/",
5357+
"search": "",
5358+
"hash": ""
5359+
},
5360+
{
5361+
"input": "file://1.2.3.4/C:/",
5362+
"base": "about:blank",
5363+
"href": "file:///C:/",
5364+
"protocol": "file:",
5365+
"username": "",
5366+
"password": "",
5367+
"host": "",
5368+
"hostname": "",
5369+
"port": "",
5370+
"pathname": "/C:/",
5371+
"search": "",
5372+
"hash": ""
5373+
},
5374+
{
5375+
"input": "file://[1::8]/C:/",
5376+
"base": "about:blank",
5377+
"href": "file:///C:/",
5378+
"protocol": "file:",
5379+
"username": "",
5380+
"password": "",
5381+
"host": "",
5382+
"hostname": "",
5383+
"port": "",
5384+
"pathname": "/C:/",
5385+
"search": "",
5386+
"hash": ""
5387+
},
53455388
"# file URLs without base URL by Rimas Misevičius",
53465389
{
53475390
"input": "file:",

0 commit comments

Comments
 (0)