From 945eb5eba6695dfac323ecd9a0ba27e94b612cd8 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Thu, 4 Apr 2024 09:44:43 -0600 Subject: fix(runtime): fix Windows permission prompt (#23212) Followup to https://github.com/denoland/deno/pull/23184 --- runtime/permissions/prompter.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'runtime') 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, -- cgit v1.2.3