Browse Source

pathname setter tests and fixes

Simon Sapin 10 năm trước cách đây
mục cha
commit
680d93c41d
2 tập tin đã thay đổi với 72 bổ sung2 xóa
  1. 1 1
      src/parser.rs
  2. 71 1
      tests/setters_tests.json

+ 1 - 1
src/parser.rs

@@ -748,7 +748,7 @@ impl<'a> Parser<'a> {
         let mut iter = input.chars();
         let mut iter = input.chars();
         match iter.next() {
         match iter.next() {
             Some('/') => input = iter.as_str(),
             Some('/') => input = iter.as_str(),
-            Some('\\') => {
+            Some('\\') if scheme_type.is_special() => {
                 self.syntax_violation("backslash");
                 self.syntax_violation("backslash");
                 input = iter.as_str()
                 input = iter.as_str()
             }
             }

+ 71 - 1
tests/setters_tests.json

@@ -922,7 +922,77 @@
             }
             }
         }
         }
     ],
     ],
-    "pathname": [],
+    "pathname": [
+        {
+            "comment": "Cannot-be-a-base don’t have a path",
+            "href": "mailto:me@example.net",
+            "new_value": "/foo",
+            "expected": {
+                "href": "mailto:me@example.net",
+                "pathname": "me@example.net"
+            }
+        },
+        {
+            "href": "unix:/run/foo.socket?timeout=10",
+            "new_value": "/var/log/../run/bar.socket",
+            "expected": {
+                "href": "unix:/var/run/bar.socket?timeout=10",
+                "pathname": "/var/run/bar.socket"
+            }
+        },
+        {
+            "href": "https://example.net#nav",
+            "new_value": "home",
+            "expected": {
+                "href": "https://example.net/home#nav",
+                "pathname": "/home"
+            }
+        },
+        {
+            "href": "https://example.net#nav",
+            "new_value": "../home",
+            "expected": {
+                "href": "https://example.net/home#nav",
+                "pathname": "/home"
+            }
+        },
+        {
+            "comment": "\\ is a segment delimiter for 'special' URLs",
+            "href": "http://example.net/home?lang=fr#nav",
+            "new_value": "\\a\\%2E\\b\\%2e.\\c",
+            "expected": {
+                "href": "http://example.net/a/c?lang=fr#nav",
+                "pathname": "/a/c"
+            }
+        },
+        {
+            "comment": "\\ is *not* a segment delimiter for non-'special' URLs",
+            "href": "view-source+http://example.net/home?lang=fr#nav",
+            "new_value": "\\a\\%2E\\b\\%2e.\\c",
+            "expected": {
+                "href": "view-source+http://example.net/\\a\\.\\b\\..\\c?lang=fr#nav",
+                "pathname": "/\\a\\.\\b\\..\\c"
+            }
+        },
+        {
+            "comment": "UTF-8 percent encoding with the default encode set. Tabs and newlines are removed.",
+            "href": "a:/",
+            "new_value": "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
+            "expected": {
+                "href": "a:/%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9",
+                "pathname": "/%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9"
+            }
+        },
+        {
+            "comment": "Bytes already percent-encoded are left as-is, except %2E.",
+            "href": "http://example.net",
+            "new_value": "%c3%89t%c3%a9%2e%2E",
+            "expected": {
+                "href": "http://example.net/%c3%89t%c3%a9..",
+                "pathname": "/%c3%89t%c3%a9.."
+            }
+        }
+   ],
     "search": [],
     "search": [],
     "hash": []
     "hash": []
 }
 }