1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00
This commit is contained in:
Yazan AbdAl-Rahman 2025-01-19 21:16:45 -06:00 committed by GitHub
commit 4d81167cca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 2 deletions

View file

@ -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<AccessCheckCb>,
@ -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

View file

@ -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
}
}
}