diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-04-04 09:44:43 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 09:44:43 -0600 |
commit | 945eb5eba6695dfac323ecd9a0ba27e94b612cd8 (patch) | |
tree | 5407e1acecffc414315605ebc345a0df8a3e17d2 | |
parent | e01bc09573ccfee7f862c9ba2fdd7e829353b14e (diff) |
fix(runtime): fix Windows permission prompt (#23212)
Followup to https://github.com/denoland/deno/pull/23184
-rw-r--r-- | runtime/permissions/prompter.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index f75fe466a..42567b1e9 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -335,7 +335,8 @@ impl PermissionPrompter for TtyPrompter { let value = loop { // Clear stdin each time we loop around in case the user accidentally pasted // multiple lines or otherwise did something silly to generate a torrent of - // input. + // input. This doesn't work on Windows because `clear_stdin` has other side-effects. + #[cfg(unix)] if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) { eprintln!("Error clearing stdin for permission prompt. {err:#}"); return PromptResponse::Deny; // don't grant permission if this fails @@ -343,14 +344,11 @@ impl PermissionPrompter for TtyPrompter { let mut input = String::new(); let result = stdin_lock.read_line(&mut input); - if result.is_err() || input.len() > 2 { + let input = input.trim_end_matches(|c| c == '\r' || c == '\n'); + if result.is_err() || input.len() != 1 { break PromptResponse::Deny; }; - let ch = match input.chars().next() { - None => break PromptResponse::Deny, - Some(v) => v, - }; - match ch { + match input.as_bytes()[0] as char { 'y' | 'Y' => { clear_n_lines( &mut stderr_lock, |