From fd38dbab3dd5e20f37c8496f82355a4190e53d80 Mon Sep 17 00:00:00 2001 From: yazan-abdalrahman Date: Tue, 24 Sep 2024 17:28:50 +0300 Subject: [PATCH] fix and add test --- ext/fs/std_fs.rs | 2 ++ .../eval/check_device_paths/__test__.jsonc | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index cee8b3309b..2799cd243e 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -1057,6 +1057,8 @@ pub fn open_with_access_check( let is_windows_device_path = cfg!(windows) && (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 { diff --git a/tests/specs/eval/check_device_paths/__test__.jsonc b/tests/specs/eval/check_device_paths/__test__.jsonc index 761e9c07ec..047fc4d985 100644 --- a/tests/specs/eval/check_device_paths/__test__.jsonc +++ b/tests/specs/eval/check_device_paths/__test__.jsonc @@ -21,6 +21,26 @@ "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()})",