diff --git a/src/input.rs b/src/input.rs index 08125507f..a5d8d83a0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -495,10 +495,9 @@ impl Inputter { self.input_function_args.push(arg); } - pub fn function_pop_arg(&mut self) -> char { + pub fn function_pop_arg(&mut self) -> Option { self.input_function_args .pop() - .expect("function_pop_arg underflow") } fn function_push_args(&mut self, code: ReadlineCmd) { diff --git a/src/reader.rs b/src/reader.rs index 82631bcf2..01cef7fa8 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3072,10 +3072,11 @@ impl ReaderData { _ => unreachable!(), }; let (elt, _el) = self.active_edit_line(); - let target = self.inputter.function_pop_arg(); - let success = self.jump(direction, precision, elt, target); + if let Some(target) = self.inputter.function_pop_arg() { + let success = self.jump(direction, precision, elt, target); - self.inputter.function_set_status(success); + self.inputter.function_set_status(success); + } } rl::RepeatJump => { let (elt, _el) = self.active_edit_line(); diff --git a/tests/pexpects/bind.py b/tests/pexpects/bind.py index ef4709a61..9636a0cf1 100644 --- a/tests/pexpects/bind.py +++ b/tests/pexpects/bind.py @@ -372,6 +372,10 @@ send('\x07') # ctrl-g send('\r') expect_prompt("foobar") +# This should do nothing instead of crash +sendline("commandline -f backward-jump") +expect_prompt() + # Check that the builtin version of `exit` works # (for obvious reasons this MUST BE LAST) sendline("function myexit; echo exit; exit; end; bind ctrl-z myexit")