فهرست منبع

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 https://github.com/w3c/web-platform-tests/commit/634175d64d1f3ec26e2a674b294e71738624c77c corresponding to URL change https://github.com/whatwg/url/issues/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 -->
bors-servo 9 سال پیش
والد
کامیت
c6284a2101
2فایلهای تغییر یافته به همراه52 افزوده شده و 3 حذف شده
  1. 9 3
      src/parser.rs
  2. 43 0
      tests/urltestdata.json

+ 9 - 3
src/parser.rs

@@ -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)
@@ -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 {

+ 43 - 0
tests/urltestdata.json

@@ -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:",