Skip to content

Commit bfcda54

Browse files
committed
trim file paths if needed.
1 parent cb87418 commit bfcda54

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,12 +1403,8 @@ impl Url {
14031403
}
14041404
parser.parse_cannot_be_a_base_path(parser::Input::new(path));
14051405
} else {
1406-
let path_start = parser.serialization.len();
14071406
let mut has_host = true; // FIXME
14081407
parser.parse_path_start(scheme_type, &mut has_host, parser::Input::new(path));
1409-
if scheme_type.is_file() {
1410-
parser::trim_path(&mut parser.serialization, path_start);
1411-
}
14121408
}
14131409
});
14141410
self.restore_after_path(old_after_path_pos, &after_path);

src/parser.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ impl<'a> Parser<'a> {
540540
self.parse_path(SchemeType::File, &mut has_host, path_start, remaining)
541541
};
542542

543-
trim_path(&mut self.serialization, host_end as usize);
544543
// For file URLs that have a host and whose path starts
545544
// with the windows drive letter we just remove the host.
546545
if !has_host {
@@ -598,8 +597,6 @@ impl<'a> Parser<'a> {
598597

599598
let host_start = host_start as u32;
600599

601-
trim_path(&mut self.serialization, host_end);
602-
603600
let (query_start, fragment_start) =
604601
self.parse_query_and_fragment(scheme_type, scheme_end, remaining)?;
605602

@@ -1287,6 +1284,15 @@ impl<'a> Parser<'a> {
12871284
break;
12881285
}
12891286
}
1287+
if scheme_type.is_file() {
1288+
// while url’s path’s size is greater than 1
1289+
// and url’s path[0] is the empty string,
1290+
// validation error, remove the first item from url’s path.
1291+
//FIXME: log violation
1292+
let path = self.serialization.split_off(path_start);
1293+
self.serialization.push('/');
1294+
self.serialization.push_str(&path.trim_start_matches("/"));
1295+
}
12901296
input
12911297
}
12921298

@@ -1495,18 +1501,6 @@ impl<'a> Parser<'a> {
14951501
}
14961502
}
14971503

1498-
// Trim path start forward slashes when no authority is present
1499-
// https://github.com/whatwg/url/issues/232
1500-
pub fn trim_path(serialization: &mut String, path_start: usize) {
1501-
let path = serialization.split_off(path_start);
1502-
if path.starts_with("/") {
1503-
serialization.push('/');
1504-
serialization.push_str(&path.trim_start_matches("/"));
1505-
} else {
1506-
serialization.push_str(&path);
1507-
}
1508-
}
1509-
15101504
#[inline]
15111505
fn is_ascii_hex_digit(c: char) -> bool {
15121506
matches!(c, 'a'..='f' | 'A'..='F' | '0'..='9')

0 commit comments

Comments
 (0)