From 34c09b18160d7f802655b74b26d07b69501c3b65 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 16 Jan 2024 18:10:24 +0100 Subject: [PATCH] reader: Fix infinite loop for up/downcase bindings This could *probably* be rewritten nicer with a for-loop Fixes #10222 --- src/reader.rs | 3 ++- tests/pexpects/bind.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/reader.rs b/src/reader.rs index 77671a132..2c8b79ce0 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2795,7 +2795,7 @@ impl ReaderData { let mut capitalized_first = false; // We apply the operation from the current location to the end of the word. - let pos = el.position(); + let mut pos = el.position(); let init_pos = pos; self.move_word( elt, @@ -2824,6 +2824,7 @@ impl ReaderData { replacement.extend(chr.to_lowercase()); }; capitalized_first = capitalized_first || make_uppercase; + pos = pos + 1; } self.replace_substring(elt, init_pos..pos, replacement); self.update_buff_pos(elt, None); diff --git a/tests/pexpects/bind.py b/tests/pexpects/bind.py index 9d9e57707..67bac5286 100644 --- a/tests/pexpects/bind.py +++ b/tests/pexpects/bind.py @@ -375,6 +375,11 @@ expect_prompt() send("\x1A") expect_str("bound ctrl-z") +send('echo foobar') +send('\x02\x02\x02') # ctrl-b, backward-char +sendline('\x1bu') # alt+u, upcase word +expect_prompt("fooBAR") + # Check that the builtin version of `exit` works # (for obvious reasons this MUST BE LAST) sendline("function myexit; echo exit; exit; end; bind \cz myexit")