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

Also fix issue where path segment could be confused with drive letter because we don't check if the path is empty

Valentin Gosu 3 лет назад
Родитель
Сommit
df88a29c91
2 измененных файлов с 14 добавлено и 1 удалено
  1. 1 1
      url/src/parser.rs
  2. 13 0
      url/tests/unit.rs

+ 1 - 1
url/src/parser.rs

@@ -1254,7 +1254,7 @@ impl<'a> Parser<'a> {
                 }
                 _ => {
                     // If url’s scheme is "file", url’s path is empty, and buffer is a Windows drive letter, then
-                    if scheme_type.is_file() && is_windows_drive_letter(segment_before_slash) {
+                    if scheme_type.is_file() && segment_start == path_start + 1 && is_windows_drive_letter(segment_before_slash) {
                         // Replace the second code point in buffer with U+003A (:).
                         if let Some(c) = segment_before_slash.chars().next() {
                             self.serialization.truncate(segment_start);

+ 13 - 0
url/tests/unit.rs

@@ -1285,3 +1285,16 @@ fn test_file_with_drive() {
         assert_eq!(url2.to_string(), case.1);
     }
 }
+
+#[test]
+/// Similar to test_file_with_drive, but with a path
+/// that could be confused for a drive.
+fn test_file_with_drive_and_path() {
+    let s1 = "fIlE:p:/x|?../";
+    let url = url::Url::parse(s1).unwrap();
+    assert_eq!(url.to_string(), "file:///p:/x|?../");
+    assert_eq!(url.path(), "/p:/x|");
+    let s2 = "a";
+    let url2 = url::Url::join(&url, s2).unwrap();
+    assert_eq!(url2.to_string(), "file:///p:/a");
+}