From df88a29c9176435aeef786145af3572bf8747d05 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Wed, 31 May 2023 01:00:36 +0300 Subject: [PATCH] Also fix issue where path segment could be confused with drive letter because we don't check if the path is empty --- url/src/parser.rs | 2 +- url/tests/unit.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/url/src/parser.rs b/url/src/parser.rs index 946ac860d..ea4c88cd7 100644 --- a/url/src/parser.rs +++ b/url/src/parser.rs @@ -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); diff --git a/url/tests/unit.rs b/url/tests/unit.rs index cd67594c6..6cb0f37fe 100644 --- a/url/tests/unit.rs +++ b/url/tests/unit.rs @@ -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"); +}