Skip to content

Commit

Permalink
Also fix issue where path segment could be confused with drive letter…
Browse files Browse the repository at this point in the history
… because we don't check if the path is empty
  • Loading branch information
valenting committed May 30, 2023
1 parent 5432fd8 commit df88a29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit df88a29

Please sign in to comment.