diff options
| author | Chris Denton <chris@chrisdenton.dev> | 2025-03-24 18:57:07 +0000 |
|---|---|---|
| committer | Chris Denton <chris@chrisdenton.dev> | 2025-04-09 01:32:19 +0000 |
| commit | edfc74722556c659de6fa03b23af3b9c8ceb8ac2 (patch) | |
| tree | c692897e9ff5a2a2731ffcab109a18e56574a4d1 /library/std/src/sys/path/windows | |
| parent | a6e4d0308632f09c1041454a82d16527222e4b32 (diff) | |
| download | rust-edfc74722556c659de6fa03b23af3b9c8ceb8ac2.tar.gz rust-edfc74722556c659de6fa03b23af3b9c8ceb8ac2.zip | |
Avoid verbatim paths in Command::current_dir
If possible, we should try not to use verbatim paths in Command::current_dir. It might work but it might also break code (including some Windows APIs) that assume the current directory isn't verbatim.
Diffstat (limited to 'library/std/src/sys/path/windows')
| -rw-r--r-- | library/std/src/sys/path/windows/tests.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/library/std/src/sys/path/windows/tests.rs b/library/std/src/sys/path/windows/tests.rs index f2a60e30bc6..9eb79203dca 100644 --- a/library/std/src/sys/path/windows/tests.rs +++ b/library/std/src/sys/path/windows/tests.rs @@ -135,3 +135,15 @@ fn broken_unc_path() { assert_eq!(components.next(), Some(Component::Normal("foo".as_ref()))); assert_eq!(components.next(), Some(Component::Normal("bar".as_ref()))); } + +#[test] +fn test_is_absolute_exact() { + use crate::sys::pal::api::wide_str; + // These paths can be made verbatim by only changing their prefix. + assert!(is_absolute_exact(wide_str!(r"C:\path\to\file"))); + assert!(is_absolute_exact(wide_str!(r"\\server\share\path\to\file"))); + // These paths change more substantially + assert!(!is_absolute_exact(wide_str!(r"C:\path\to\..\file"))); + assert!(!is_absolute_exact(wide_str!(r"\\server\share\path\to\..\file"))); + assert!(!is_absolute_exact(wide_str!(r"C:\path\to\NUL"))); // Converts to \\.\NUL +} |
