diff --git a/src/common/non_utf8/path.rs b/src/common/non_utf8/path.rs index 53f8b16..fc91b35 100644 --- a/src/common/non_utf8/path.rs +++ b/src/common/non_utf8/path.rs @@ -658,8 +658,16 @@ where } else { // Get the cwd as a platform path and convert to this path's encoding let cwd = crate::utils::current_dir()?.with_encoding(); + let joined = cwd.join(self); - Ok(cwd.join(self).normalize()) + if !joined.is_absolute() { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "path cannot be absolutized without ambiguity", + )) + } else { + Ok(joined.normalize()) + } } } diff --git a/src/windows.rs b/src/windows.rs index f953770..f755ef8 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -4,3 +4,31 @@ mod utf8; pub use non_utf8::*; pub use utf8::*; + +#[cfg(feature = "std")] +#[test] +fn absolutize_should_fail_for_windows_path_with_drive_letter_only_prefix() { + let p = WindowsPath::new(r"C:something"); + assert!(p.absolutize().is_err()) +} + +#[cfg(feature = "std")] +#[test] +fn absolutize_should_fail_for_windows_path_with_verbatim_drive_letter_only_prefix() { + let p = WindowsPath::new(r"\\?\C:something"); + assert!(p.absolutize().is_err()) +} + +#[cfg(feature = "std")] +#[test] +fn absolutize_should_fail_for_windows_path_with_unc_server_only_prefix() { + let p = WindowsPath::new(r"\\server"); + assert!(p.absolutize().is_err()) +} + +#[cfg(feature = "std")] +#[test] +fn absolutize_should_fail_for_windows_path_with_verbatim_unc_server_only_prefix() { + let p = WindowsPath::new(r"\\?\UNC\server"); + assert!(p.absolutize().is_err()) +}