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

Non-special URLs can have their paths erased (#921)

DylanOToole2 2 лет назад
Родитель
Сommit
fd042e003f
2 измененных файлов с 6 добавлено и 2 удалено
  1. 6 1
      url/src/quirks.rs
  2. 0 1
      url/tests/expected_failures.txt

+ 6 - 1
url/src/quirks.rs

@@ -279,10 +279,15 @@ pub fn set_pathname(url: &mut Url, new_pathname: &str) {
             && new_pathname.starts_with('\\'))
     {
         url.set_path(new_pathname)
-    } else {
+    } else if SchemeType::from(url.scheme()).is_special()
+        || !new_pathname.is_empty()
+        || !url.has_host()
+    {
         let mut path_to_set = String::from("/");
         path_to_set.push_str(new_pathname);
         url.set_path(&path_to_set)
+    } else {
+        url.set_path(new_pathname)
     }
 }
 

+ 0 - 1
url/tests/expected_failures.txt

@@ -38,7 +38,6 @@
 <http://example.net:8080/path> set hostname to <example.com:>
 <non-spec:/.//p> set hostname to <h>
 <non-spec:/.//p> set hostname to <>
-<foo://somehost/some/path> set pathname to <>
 <foo:///some/path> set pathname to <>
 <http://example.net:8080/path> set port to <randomstring>
 <file:///var/log/system.log> set href to <http://0300.168.0xF0>