From 3475531ef7e81f301ee0247cda2ee4c3c769e54c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 30 Dec 2024 08:12:32 +0100 Subject: [PATCH] Also ignore invalid recursive escape sequences We parse "\e\e[x" as alt-modified "Invalid" key. Due to this extra modifier, we accidentally add it to the input queue, instead of dropping this invalid key. We don't really want to try to extract some valid keys from this invalid sequence, see also the parent commit. This allows us to remove misplaced validation that was added by e8e91c97a6 (fish_key_reader: ignore sentinel key, 2024-04-02) but later obsoleted by 66c6e89f98 (Don't add collateral sentinel key to input queue, 2024-04-03). (cherry picked from commit 84f19a931d609e3ca6ecc2d53234427887f2f0f5) --- src/bin/fish_key_reader.rs | 5 +---- src/input_common.rs | 6 +++++- src/key.rs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/bin/fish_key_reader.rs b/src/bin/fish_key_reader.rs index b401621b1..7412b27fc 100644 --- a/src/bin/fish_key_reader.rs +++ b/src/bin/fish_key_reader.rs @@ -23,7 +23,7 @@ terminal_protocol_hacks, terminal_protocols_enable_ifn, CharEvent, InputEventQueue, InputEventQueuer, }, - key::{self, char_to_symbol, Key}, + key::{char_to_symbol, Key}, panic::panic_handler, print_help::print_help, printf, @@ -101,9 +101,6 @@ fn process_input(continuous_mode: bool, verbose: bool) -> i32 { continue; }; let c = kevt.key.codepoint; - if c == key::Invalid { - continue; - } if verbose { printf!("# decoded from: "); for byte in kevt.seq.chars() { diff --git a/src/input_common.rs b/src/input_common.rs index 704bfbb72..eaa253dfc 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -691,6 +691,7 @@ fn try_readch(&mut self, blocking: bool) -> Option { if key == Some(Key::from_raw(key::Invalid)) { continue; } + assert!(key.map_or(true, |key| key.codepoint != key::Invalid)); let mut consumed = 0; let mut state = zero_mbstate(); let mut i = 0; @@ -767,10 +768,13 @@ fn parse_escape_sequence( return Some( match self.parse_escape_sequence(buffer, have_escape_prefix) { Some(mut nested_sequence) => { + if nested_sequence == invalid { + return Some(Key::from_raw(key::Escape)); + } nested_sequence.modifiers.alt = true; nested_sequence } - None => invalid, + _ => invalid, }, ); } diff --git a/src/key.rs b/src/key.rs index 7b8346ff5..59a8ce56e 100644 --- a/src/key.rs +++ b/src/key.rs @@ -23,7 +23,7 @@ pub(crate) const Insert: char = '\u{F50c}'; pub(crate) const Tab: char = '\u{F50d}'; pub(crate) const Space: char = '\u{F50e}'; -pub const Invalid: char = '\u{F50f}'; +pub(crate) const Invalid: char = '\u{F50f}'; pub(crate) fn function_key(n: u32) -> char { assert!((1..=12).contains(&n)); char::from_u32(u32::from(Invalid) + n).unwrap()