From 03115cc5f17f45cfeaee22197bc6b9fff003d692 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 17 Mar 2021 08:33:42 +0000 Subject: libbb: fix another tab-completion corner case Commit 90f35327c (libbb: avoid problems with quoted characters in tab completion) avoided a conflict between the code to quote special characters and that to display case-preserved filenames. Here's another one. I'd installed a third-party binary on Microsoft Windows and wanted to execute it from a busybox-w32 shell which didn't have it in its path. No problem: $ c:/prog $ c:/Program Program Files/ ProgramData $ c:/Program\ $ c:/PProgram I was too quick to enter the final , I'd meant to add a space. A trailing backslash is effectively removed by the tab completion matching code but it remains on the display. This confuses the code to display case-preserved filenames. Upstream BusyBox just ends up with a spurious backslash in the name. Bash rewrites the command line to remove the surplus backslash. Fix the issue in busybox-w32 by leaving the backslash in the name, even for matching purposes. This will never result in a match, thus affording the user a change to correct their mistake. --- libbb/lineedit.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 205044630..c20436270 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1046,7 +1046,13 @@ static NOINLINE int build_match_prefix(char *match_buf) /* Mark every \c as "quoted c" */ for (i = 0; int_buf[i]; i++) { +#if ENABLE_PLATFORM_MINGW32 + /* Trailing backslash is effectively removed which confuses + * the code to display case-preserved filenames. */ + if (int_buf[i] == '\\' && int_buf[i+1] != '\0') { +#else if (int_buf[i] == '\\') { +#endif remove_chunk(int_buf, i, i + 1); int_buf[i] |= QUOT; } -- cgit v1.2.3-55-g6feb