From c5e5da5eb1e0f6acee26bc22d2f567406a2840bc Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 29 Dec 2024 10:56:48 +0000 Subject: ash: strip trailing slash from directory if necessary The previous commit removed trailing dots and spaces from the last component of a pathname when changing directory. If the result has a trailing slash remove that too. But not if it's a drive root, to avoid 'cd C:/' showing a current directory of 'C:'. Adds 48 bytes. (GitHub issue #478) --- win32/mingw.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/win32/mingw.c b/win32/mingw.c index 6842dba48..7a5198ccf 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -2189,6 +2189,11 @@ void FAST_FUNC strip_dot_space(char *p) while (end > start && (end[-1] == '.' || end[-1] == ' ')) { *--end = '\0'; } + + // Strip trailing slash, but not from a drive root (C:/) + if (--end != start && (*end == '/' || *end == '\\') && + !(end == p + 2 && root_len(p) == 2)) + *end = '\0'; } size_t FAST_FUNC remove_cr(char *p, size_t len) -- cgit v1.2.3-55-g6feb