aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-02-12 13:57:26 +0000
committerRon Yorston <rmy@pobox.com>2021-02-12 13:57:26 +0000
commit90f35327c2f31b7e4d938bf4d54e5526e53daee0 (patch)
tree07daa2ce1f0546a435d7e3b0d5d9db5ef00bd229
parent038bc6cc76f1099b05eba30da64ed7b639af0245 (diff)
downloadbusybox-w32-90f35327c2f31b7e4d938bf4d54e5526e53daee0.tar.gz
busybox-w32-90f35327c2f31b7e4d938bf4d54e5526e53daee0.tar.bz2
busybox-w32-90f35327c2f31b7e4d938bf4d54e5526e53daee0.zip
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<TAB> 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\+
-rw-r--r--libbb/lineedit.c14
1 files 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)
1249 size_t len_found; 1249 size_t len_found;
1250 /* Length of string used for matching */ 1250 /* Length of string used for matching */
1251 unsigned match_pfx_len = match_pfx_len; 1251 unsigned match_pfx_len = match_pfx_len;
1252#if ENABLE_PLATFORM_MINGW32
1253 unsigned orig_pfx_len;
1254#endif
1252 int find_type; 1255 int find_type;
1253# if ENABLE_UNICODE_SUPPORT 1256# if ENABLE_UNICODE_SUPPORT
1254 /* cursor pos in command converted to multibyte form */ 1257 /* cursor pos in command converted to multibyte form */
@@ -1313,6 +1316,9 @@ static NOINLINE void input_tab(smallint *lastWasTab)
1313 { 1316 {
1314 const char *e = match_buf + strlen(match_buf); 1317 const char *e = match_buf + strlen(match_buf);
1315 const char *s = e - match_pfx_len; 1318 const char *s = e - match_pfx_len;
1319#if ENABLE_PLATFORM_MINGW32
1320 orig_pfx_len = match_pfx_len;
1321#endif
1316 while (s < e) 1322 while (s < e)
1317 if (is_special_char(*s++)) 1323 if (is_special_char(*s++))
1318 match_pfx_len++; 1324 match_pfx_len++;
@@ -1388,10 +1394,12 @@ static NOINLINE void input_tab(smallint *lastWasTab)
1388 strcpy(match_buf, &command_ps[cursor]); 1394 strcpy(match_buf, &command_ps[cursor]);
1389 /* add match and tail */ 1395 /* add match and tail */
1390#if ENABLE_PLATFORM_MINGW32 1396#if ENABLE_PLATFORM_MINGW32
1391 sprintf(&command_ps[cursor-match_pfx_len], "%s%s", chosen_match, match_buf); 1397 if (match_pfx_len == orig_pfx_len) {
1392#else 1398 sprintf(&command_ps[cursor-match_pfx_len], "%s%s",
1393 sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf); 1399 chosen_match, match_buf);
1400 } else
1394#endif 1401#endif
1402 sprintf(&command_ps[cursor], "%s%s", chosen_match + match_pfx_len, match_buf);
1395 command_len = strlen(command_ps); 1403 command_len = strlen(command_ps);
1396 /* new pos */ 1404 /* new pos */
1397 pos = cursor + len_found - match_pfx_len; 1405 pos = cursor + len_found - match_pfx_len;