From 7e6b94231290020b55f1d08fb03ea8132781abc5 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sun, 18 Feb 2024 21:51:06 -0700 Subject: feat(core): highlight unprintable chars in permission prompts (#22468) If we strip out unprintable chars, we don't see the full filename being requested by permission prompts. Instead, we highlight and escape them to make them visible. --- tests/integration/run_tests.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 02fb915b5..a4bfc6345 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -4725,19 +4725,19 @@ fn stdio_streams_are_locked_in_permission_prompt() { } #[test] -fn permission_prompt_strips_ansi_codes_and_control_chars() { +fn permission_prompt_escapes_ansi_codes_and_control_chars() { util::with_pty(&["repl"], |mut console| { console.write_line( r#"Deno.permissions.request({ name: "env", variable: "\rDo you like ice cream? y/n" });"# ); // will be uppercase on windows let env_name = if cfg!(windows) { - "DO YOU LIKE ICE CREAM? Y/N" + "\\rDO YOU LIKE ICE CREAM? Y/N" } else { - "Do you like ice cream? y/n" + "\\rDo you like ice cream? y/n" }; console.expect(format!( - "┌ ⚠️ Deno requests env access to \"{}\".", + "\u{250c} \u{26a0}\u{fe0f} Deno requests env access to \"{}\".", env_name )) }); @@ -4747,14 +4747,10 @@ fn permission_prompt_strips_ansi_codes_and_control_chars() { console.expect("undefined"); console.write_line_raw(r#"const unboldANSI = "\u001b[22m";"#); console.expect("undefined"); - console.write_line_raw(r#"const prompt = `┌ ⚠️ ${boldANSI}Deno requests run access to "echo"${unboldANSI}\n ├ Requested by \`Deno.Command().output()`"#); - console.expect("undefined"); - console.write_line_raw(r#"const moveANSIUp = "\u001b[1A";"#); - console.expect("undefined"); - console.write_line_raw(r#"const clearANSI = "\u001b[2K";"#); - console.expect("undefined"); - console.write_line_raw(r#"const moveANSIStart = "\u001b[1000D";"#); - console.expect("undefined"); + console.write_line_raw( + r#"new Deno.Command(`${boldANSI}cat${unboldANSI}`).spawn();"#, + ); + console.expect("\u{250c} \u{26a0}\u{fe0f} Deno requests run access to \"\\u{1b}[1mcat\\u{1b}[22m\"."); }); } -- cgit v1.2.3