summaryrefslogtreecommitdiff
path: root/ext/fs/std_fs.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-05-08 14:39:06 -0600
committerGitHub <noreply@github.com>2024-05-08 14:39:06 -0600
commit9f7f681e26887a9b284a2f25e8252c3a5077f348 (patch)
tree19315e1b11ab3597b2055966b8b6dd93780af298 /ext/fs/std_fs.rs
parent547ce6c3b82c5e0c04dfb902f609cb229a2bde9a (diff)
fix(runtime): allow nul device on windows (#23741)
Fixes [23721](https://github.com/denoland/deno/issues/23721)
Diffstat (limited to 'ext/fs/std_fs.rs')
-rw-r--r--ext/fs/std_fs.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs
index 6bc15a72d..9e2acedcc 100644
--- a/ext/fs/std_fs.rs
+++ b/ext/fs/std_fs.rs
@@ -890,7 +890,15 @@ fn open_with_access_check(
access_check: Option<AccessCheckCb>,
) -> FsResult<std::fs::File> {
if let Some(access_check) = access_check {
- let path = if path.is_absolute() {
+ let path_bytes = path.as_os_str().as_encoded_bytes();
+ let is_windows_device_path = cfg!(windows)
+ && path_bytes.starts_with(br"\\.\")
+ && !path_bytes.contains(&b':');
+ let path = if is_windows_device_path {
+ // On Windows, normalize_path doesn't work with device-prefix-style
+ // paths. We pass these through.
+ path.to_owned()
+ } else if path.is_absolute() {
normalize_path(path)
} else {
let cwd = current_dir()?;
@@ -898,8 +906,8 @@ fn open_with_access_check(
};
(*access_check)(false, &path, &options)?;
// On Linux, /proc may contain magic links that we don't want to resolve
- let needs_canonicalization =
- !cfg!(target_os = "linux") || path.starts_with("/proc");
+ let needs_canonicalization = !is_windows_device_path
+ && (!cfg!(target_os = "linux") || path.starts_with("/proc"));
let path = if needs_canonicalization {
match path.canonicalize() {
Ok(path) => path,
@@ -916,7 +924,6 @@ fn open_with_access_check(
} else {
path
};
-
(*access_check)(true, &path, &options)?;
// For windows