Jeremy Lempereur 6 лет назад
Родитель
Сommit
aeef54febe
2 измененных файлов с 9 добавлено и 19 удалено
  1. 0 4
      src/lib.rs
  2. 9 15
      src/parser.rs

+ 0 - 4
src/lib.rs

@@ -1403,12 +1403,8 @@ impl Url {
                 }
                 parser.parse_cannot_be_a_base_path(parser::Input::new(path));
             } else {
-                let path_start = parser.serialization.len();
                 let mut has_host = true; // FIXME
                 parser.parse_path_start(scheme_type, &mut has_host, parser::Input::new(path));
-                if scheme_type.is_file() {
-                    parser::trim_path(&mut parser.serialization, path_start);
-                }
             }
         });
         self.restore_after_path(old_after_path_pos, &after_path);

+ 9 - 15
src/parser.rs

@@ -540,7 +540,6 @@ impl<'a> Parser<'a> {
                     self.parse_path(SchemeType::File, &mut has_host, path_start, remaining)
                 };
 
-                trim_path(&mut self.serialization, host_end as usize);
                 // For file URLs that have a host and whose path starts
                 // with the windows drive letter we just remove the host.
                 if !has_host {
@@ -598,8 +597,6 @@ impl<'a> Parser<'a> {
 
                 let host_start = host_start as u32;
 
-                trim_path(&mut self.serialization, host_end);
-
                 let (query_start, fragment_start) =
                     self.parse_query_and_fragment(scheme_type, scheme_end, remaining)?;
 
@@ -1287,6 +1284,15 @@ impl<'a> Parser<'a> {
                 break;
             }
         }
+        if scheme_type.is_file() {
+            // while url’s path’s size is greater than 1
+            // and url’s path[0] is the empty string,
+            // validation error, remove the first item from url’s path.
+            //FIXME: log violation
+            let path = self.serialization.split_off(path_start);
+            self.serialization.push('/');
+            self.serialization.push_str(&path.trim_start_matches("/"));
+        }
         input
     }
 
@@ -1495,18 +1501,6 @@ impl<'a> Parser<'a> {
     }
 }
 
-// Trim path start forward slashes when no authority is present
-// https://github.com/whatwg/url/issues/232
-pub fn trim_path(serialization: &mut String, path_start: usize) {
-    let path = serialization.split_off(path_start);
-    if path.starts_with("/") {
-        serialization.push('/');
-        serialization.push_str(&path.trim_start_matches("/"));
-    } else {
-        serialization.push_str(&path);
-    }
-}
-
 #[inline]
 fn is_ascii_hex_digit(c: char) -> bool {
     matches!(c, 'a'..='f' | 'A'..='F' | '0'..='9')