Просмотр исходного кода

Password setter tests and fixes

Simon Sapin 10 лет назад
Родитель
Сommit
777413d51a
2 измененных файлов с 89 добавлено и 1 удалено
  1. 1 0
      src/lib.rs
  2. 88 1
      tests/setters_tests.json

+ 1 - 0
src/lib.rs

@@ -941,6 +941,7 @@ impl Url {
             let offset = end - start;
             let offset = end - start;
             self.host_start -= offset;
             self.host_start -= offset;
             self.host_end -= offset;
             self.host_end -= offset;
+            self.path_start -= offset;
             if let Some(ref mut index) = self.query_start { *index -= offset }
             if let Some(ref mut index) = self.query_start { *index -= offset }
             if let Some(ref mut index) = self.fragment_start { *index -= offset }
             if let Some(ref mut index) = self.fragment_start { *index -= offset }
         }
         }

+ 88 - 1
tests/setters_tests.json

@@ -148,6 +148,15 @@
                 "username": ""
                 "username": ""
             }
             }
         },
         },
+        {
+            "comment": "No host means no username",
+            "href": "unix:/run/foo.socket",
+            "new_value": "me",
+            "expected": {
+                "href": "unix:/run/foo.socket",
+                "username": ""
+            }
+        },
         {
         {
             "comment": "Cannot-be-a-base means no username",
             "comment": "Cannot-be-a-base means no username",
             "href": "mailto:you@example.net",
             "href": "mailto:you@example.net",
@@ -208,7 +217,85 @@
             }
             }
         }
         }
     ],
     ],
-    "password": [],
+    "password": [
+        {
+            "comment": "No host means no password",
+            "href": "file:///home/me/index.html",
+            "new_value": "secret",
+            "expected": {
+                "href": "file:///home/me/index.html",
+                "password": ""
+            }
+        },
+        {
+            "comment": "No host means no password",
+            "href": "unix:/run/foo.socket",
+            "new_value": "secret",
+            "expected": {
+                "href": "unix:/run/foo.socket",
+                "password": ""
+            }
+        },
+        {
+            "comment": "Cannot-be-a-base means no password",
+            "href": "mailto:me@example.net",
+            "new_value": "secret",
+            "expected": {
+                "href": "mailto:me@example.net",
+                "password": ""
+            }
+        },
+        {
+            "href": "http://example.net",
+            "new_value": "secret",
+            "expected": {
+                "href": "http://:secret@example.net/",
+                "password": "secret"
+            }
+        },
+        {
+            "href": "http://me@example.net",
+            "new_value": "secret",
+            "expected": {
+                "href": "http://me:secret@example.net/",
+                "password": "secret"
+            }
+        },
+        {
+            "href": "http://:secret@example.net",
+            "new_value": "",
+            "expected": {
+                "href": "http://example.net/",
+                "password": ""
+            }
+        },
+        {
+            "href": "http://me:secret@example.net",
+            "new_value": "",
+            "expected": {
+                "href": "http://me@example.net/",
+                "password": ""
+            }
+        },
+        {
+            "comment": "UTF-8 percent encoding with the userinfo encode set.",
+            "href": "http://example.net",
+            "new_value": "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
+            "expected": {
+                "href": "http://:%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/",
+                "password": "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9"
+            }
+        },
+        {
+            "comment": "Bytes already percent-encoded are left as-is.",
+            "href": "http://example.net",
+            "new_value": "%c3%89t%c3%a9",
+            "expected": {
+                "href": "http://:%c3%89t%c3%a9@example.net/",
+                "password": "%c3%89t%c3%a9"
+            }
+        }
+    ],
     "host": [],
     "host": [],
     "hostname": [],
     "hostname": [],
     "port": [],
     "port": [],