From b5e52703e9725db591d870bc327b27ae1c47817d Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Mon, 8 Jun 2020 03:22:51 -0700 Subject: [PATCH] Fix an issue with the up arrow key in Emacs editing mode. Emacs editing mode is bugged in ksh93u+ and ksh2020. Let's say you were to run the following commands after starting a fresh instance of ksh: $ alias foo='true' $ unalias foo If you type 'a' and then press the up arrow on your keyboard, ksh will complete 'a' to `alias foo='true'` by doing a reverse search for the last command that starts with 'a'. Run the alias command again, then type 'u' and press the up arrow key again. If ksh is in Vi mode, you will get `unalias foo`, but in Emacs mode you will get `alias foo='true'` again. This bug was occurring because ksh was only doing a reverse search based on the first command that was completed using the up arrow. All subsequent commands were ignored as ksh was saving the first command and only based later searches off of it. NEWS: - Add instructions for reproducing this bug with the up arrow key and information about why this bug was happening in the first place. src/cmd/ksh93/edit/emacs.c: - Remove a bad check that was preventing ksh from using the latest input for reverse search. (cherry picked from commit 745b065487ad6bac693ec6f44752f96e87f9a63b) --- NEWS | 15 +++++++++++++++ src/cmd/ksh93/edit/emacs.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 6d4aa366f..14e58d54a 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,21 @@ Any uppercase BUG_* names are modernish shell bug IDs. 2020-06-08: + - Fix an issue with the up arrow key in Emacs editing mode. + Emacs editing mode is bugged in ksh93u+ and ksh2020. Let's + say you were to run the following commands after starting + a fresh instance of ksh: + $ alias foo='true' + $ unalias foo + If you type 'a' and then press the up arrow on your keyboard, + ksh will complete 'a' to `alias foo='true'` by doing a reverse + search for the last command that starts with 'a'. + Run the alias command again, then type 'u' and press the up + arrow key again. If ksh is in Vi mode, you will get `unalias foo`, + but in Emacs mode you will get `alias foo='true'` again. + All subsequent commands were ignored as ksh was saving the first + command and only based later searches off of it. + - If 'set -u'/'set -o nounset' is active, then the shell now errors out if a nonexistent positional parameter such as $1, $2, ... is accessed, as other shells do and POSIX requires. (This does *not* apply to "$@" and "$*".) diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index 174b47761..87def4a57 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -1073,7 +1073,7 @@ static int escape(register Emacs_t* ep,register genchar *out,int count) if(cur>0 && eol==cur && (cur<(SEARCHSIZE-2) || ep->prevdirection == -2)) #endif /* SHOPT_EDPREDICT */ { - if(ep->lastdraw==APPEND && ep->prevdirection != -2) + if(ep->lastdraw==APPEND) { out[cur] = 0; gencpy((genchar*)lstring+1,out);