From 9114e110a59a77909132af6d97bccdf5056adfa4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 29 Jun 2020 11:46:43 +0100 Subject: ash: avoid duplicated slashes in output of type/command builtins Microsoft developers have a penchant for adding trailing slashes to entries in PATH: C:/Windows/System32/WindowsPowerShell/v1.0/ C:/Windows/System32/OpenSSH/ The 'type' and 'command -v' shell builtins return paths with duplicated slashes for executables in those directories. See GitHub issue #191. Bonus fixes: - handle backslashes as well as slashes in concat_path_file() - convert backslashes to slashes in the output of 'type', 'command -v' --- libbb/concat_path_file.c | 6 ++++++ shell/ash.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c index 5b4b7f113..81c7481ca 100644 --- a/libbb/concat_path_file.c +++ b/libbb/concat_path_file.c @@ -21,8 +21,14 @@ char* FAST_FUNC concat_path_file(const char *path, const char *filename) if (!path) path = ""; +#if ENABLE_PLATFORM_MINGW32 + lc = last_char_is(path, '/') ?: last_char_is(path, '\\'); + while (*filename == '/' || *filename == '\\') + filename++; +#else lc = last_char_is(path, '/'); while (*filename == '/') filename++; +#endif return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename); } diff --git a/shell/ash.c b/shell/ash.c index b51a3fb82..3c53b25ff 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2860,6 +2860,9 @@ padvance_magic(const char **path, const char *name, int magic) if (len) { q = mempcpy(q, start, len); +#if ENABLE_PLATFORM_MINGW32 + if (q[-1] != '/' && q[-1] != '\\') +#endif *q++ = '/'; } strcpy(q, name); @@ -9160,6 +9163,7 @@ describe_command(char *command, const char *path, int describe_command_verbose) } #if ENABLE_PLATFORM_MINGW32 add_win32_extension(p); + bs_to_slash(p); #endif if (describe_command_verbose) { out1fmt(" is %s", p); -- cgit v1.2.3-55-g6feb