Skip to content

Commit df88a29

Browse files
committed
Also fix issue where path segment could be confused with drive letter because we don't check if the path is empty
1 parent 5432fd8 commit df88a29

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

url/src/parser.rs

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

url/tests/unit.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1285,3 +1285,16 @@ fn test_file_with_drive() {
12851285
assert_eq!(url2.to_string(), case.1);
12861286
}
12871287
}
1288+
1289+
#[test]
1290+
/// Similar to test_file_with_drive, but with a path
1291+
/// that could be confused for a drive.
1292+
fn test_file_with_drive_and_path() {
1293+
let s1 = "fIlE:p:/x|?../";
1294+
let url = url::Url::parse(s1).unwrap();
1295+
assert_eq!(url.to_string(), "file:///p:/x|?../");
1296+
assert_eq!(url.path(), "/p:/x|");
1297+
let s2 = "a";
1298+
let url2 = url::Url::join(&url, s2).unwrap();
1299+
assert_eq!(url2.to_string(), "file:///p:/a");
1300+
}

0 commit comments

Comments
 (0)