Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly file URLs when the path starts with a windows drive letter #410

Merged
merged 2 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ impl<'a> Parser<'a> {
self.serialization.push_str("file://");
let scheme_end = "file".len() as u32;
let host_start = "file://".len() as u32;
let (path_start, host, remaining) =
let (path_start, mut host, remaining) =
self.parse_file_host(input_after_next_char)?;
let host_end = to_u32(self.serialization.len())?;
let mut host_end = to_u32(self.serialization.len())?;
let mut has_host = !matches!(host, HostInternal::None);
let remaining = if path_start {
self.parse_path_start(SchemeType::File, &mut has_host, remaining)
Expand All @@ -487,7 +487,13 @@ impl<'a> Parser<'a> {
self.serialization.push('/');
self.parse_path(SchemeType::File, &mut has_host, path_start, remaining)
};
// FIXME: deal with has_host
// For file URLs that have a host and whose path starts
// with the windows drive letter we just remove the host.
if !has_host {
self.serialization.drain(host_start as usize..host_end as usize);
host_end = host_start;
host = HostInternal::None;
}
let (query_start, fragment_start) =
self.parse_query_and_fragment(scheme_end, remaining)?;
Ok(Url {
Expand Down
43 changes: 43 additions & 0 deletions tests/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5342,6 +5342,49 @@
"search": "",
"hash": ""
},
"# Windows drive letter quirk with not empty host",
{
"input": "file://example.net/C:/",
"base": "about:blank",
"href": "file:///C:/",
"protocol": "file:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "/C:/",
"search": "",
"hash": ""
},
{
"input": "file://1.2.3.4/C:/",
"base": "about:blank",
"href": "file:///C:/",
"protocol": "file:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "/C:/",
"search": "",
"hash": ""
},
{
"input": "file://[1::8]/C:/",
"base": "about:blank",
"href": "file:///C:/",
"protocol": "file:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "/C:/",
"search": "",
"hash": ""
},
"# file URLs without base URL by Rimas Misevičius",
{
"input": "file:",
Expand Down