Skip to content

Commit 07839af

Browse files
committed
Make sure file path is trimmed.
1 parent 15e0ef7 commit 07839af

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,12 @@ impl Url {
13361336
}
13371337
parser.parse_cannot_be_a_base_path(parser::Input::new(path));
13381338
} else {
1339+
let path_start = parser.serialization.len();
13391340
let mut has_host = true; // FIXME
13401341
parser.parse_path_start(scheme_type, &mut has_host, parser::Input::new(path));
1342+
if scheme_type.is_file() {
1343+
parser::trim_path(&mut parser.serialization, path_start);
1344+
}
13411345
}
13421346
});
13431347
self.restore_after_path(old_after_path_pos, &after_path);

src/parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,12 +1425,14 @@ impl<'a> Parser<'a> {
14251425

14261426
// Trim path start forward slashes when no authority is present
14271427
// https://github.com/whatwg/url/issues/232
1428-
fn trim_path(serialization: &mut String, path_start: usize) {
1428+
pub fn trim_path(serialization: &mut String, path_start: usize) {
14291429
let path = serialization.split_off(path_start);
14301430
if path.starts_with("/") {
14311431
let mut trimmed_path = "/".to_string();
14321432
trimmed_path.push_str(path.trim_start_matches("/"));
14331433
serialization.push_str(&trimmed_path);
1434+
} else {
1435+
serialization.push_str(&path);
14341436
}
14351437
}
14361438

0 commit comments

Comments
 (0)