From 90f35327c2f31b7e4d938bf4d54e5526e53daee0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 12 Feb 2021 13:57:26 +0000 Subject: libbb: avoid problems with quoted characters in tab completion Commit 9e341902d (libbb: copy entire match during tab-completion) adjusted the display of matches during tab completion to make any changes in case visible. Unfortunately the presence of quoted special characters upsets the display: $ touch t+1+2+3 t+1+4+5 $ ls t+1 changes the command to: $ lst\+1\+ In such cases just revert to the upstream code which only displays the tail of the match, giving: $ ls t+1\+ --- libbb/lineedit.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 27c1f3a74..4802b46b4 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1249,6 +1249,9 @@ static NOINLINE void input_tab(smallint *lastWasTab) size_t len_found; /* Length of string used for matching */ unsigned match_pfx_len = match_pfx_len; +#if ENABLE_PLATFORM_MINGW32 + unsigned orig_pfx_len; +#endif int find_type; # if ENABLE_UNICODE_SUPPORT /* cursor pos in command converted to multibyte form */ @@ -1313,6 +1316,9 @@ static NOINLINE void input_tab(smallint *lastWasTab) { const char *e = match_buf + strlen(match_buf); const char *s = e - match_pfx_len; +#if ENABLE_PLATFORM_MINGW32 + orig_pfx_len = match_pfx_len; +#endif while (s < e) if (is_special_char(*s++)) match_pfx_len++; @@ -1388,10 +1394,12 @@ static NOINLINE void input_tab(smallint *lastWasTab) strcpy(match_buf, &command_ps[cursor]); /* add match and tail */ #if ENABLE_PLATFORM_MINGW32 - sprintf(&command_ps[cursor-match_pfx_len], "%s%s", chosen_match, match_buf); -#else - sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf); + if (match_pfx_len == orig_pfx_len) { + sprintf(&command_ps[cursor-match_pfx_len], "%s%s", + chosen_match, match_buf); + } else #endif + sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf); command_len = strlen(command_ps); /* new pos */ pos = cursor + len_found - match_pfx_len; -- cgit v1.2.3-55-g6feb