diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index 4845e9c7bc..eb0b4ce5ec 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -1063,7 +1063,7 @@ fn open_options(options: OpenOptions) -> fs::OpenOptions { } #[inline(always)] -fn open_with_access_check( +pub fn open_with_access_check( options: OpenOptions, path: &Path, access_check: Option, @@ -1071,7 +1071,11 @@ fn open_with_access_check( if let Some(access_check) = access_check { let path_bytes = path.as_os_str().as_encoded_bytes(); let is_windows_device_path = cfg!(windows) - && path_bytes.starts_with(br"\\.\") + && (path_bytes.starts_with(br"\\.\") + || path_bytes.starts_with(b"//./") + || path_bytes.starts_with(b"//?/") + || path_bytes.starts_with(br"\\?\") + || path_bytes.ends_with(b"$")) && !path_bytes.contains(&b':'); let path = if is_windows_device_path { // On Windows, normalize_path doesn't work with device-prefix-style diff --git a/tests/specs/eval/check_device_paths/__test__.jsonc b/tests/specs/eval/check_device_paths/__test__.jsonc new file mode 100644 index 0000000000..047fc4d985 --- /dev/null +++ b/tests/specs/eval/check_device_paths/__test__.jsonc @@ -0,0 +1,63 @@ +{ + "tempDir": true, + "tests": { + "valid_device_paths": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('CONOUT$',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: true }\n" + }, + "valid_device_paths_i": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('CONIN$',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: true }\n" + }, + "valid_device_paths_with_prefix": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//./CONOUT$',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: true }\n" + }, + "valid_device_paths_with_prefix_i": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//./CONIN$',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: true }\n" + }, + "valid_device_paths_with_prefix_ii": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//?/CONIN$',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: true }\n" + }, + "valid_device_paths_with_prefix_iii": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//?/CONOUT$',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: true }\n" + }, + "valid_device_paths_nul_i": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//./NUL',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: false }\n" + }, + "valid_device_paths_nul_ii": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//?/NUL',{read:true,write:true}).isTerminal()})", + "output": "{ isTTY: false }\n" + }, + "invalid_device_paths": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('\\\\.\\INVALID$',{read:true,write:true}).isTerminal()})", + "output": "error: Uncaught (in promise) NotFound: The system cannot find the file specified. (os error 2): open '\\.INVALID$'\n[WILDCARD]", + "exitCode": 1 + }, + "invalid_device_paths_i": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('//./INVALID$',{read:true,write:true}).isTerminal()})", + "output": "error: Uncaught (in promise) NotFound: The system cannot find the file specified. (os error 2): open '//./INVALID$'\n[WILDCARD]", + "exitCode": 1 + }, + "invalid_device_paths_ii": { + "if": "windows", + "args": "eval console.log({isTTY:Deno.openSync('C:\\Invalid\\Path',{read:true,write:true}).isTerminal()})", + "output": "error: Uncaught (in promise) NotFound: The system cannot find the file specified. (os error 2): open 'C:InvalidPath'\n[WILDCARD]", + "exitCode": 1 + } + } +}