From bbc7c59563b13d49cbfd3fca0390829dbfca7f93 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 3 Sep 2020 16:17:45 +0200 Subject: [PATCH] browser: sort names that differ only in case with uppercase first This is the opposite of what 'ls' does in a UTF-8 locale, but nano has never followed the collating rules of Unicode (uppercase after lowercase, ignoring punctuation, and so on) -- it would be strange to change that now. Until now, nano left such equivalent names unsorted, in a seemingly random order. This fixes https://savannah.gnu.org/bugs/?59059. Bug existed since before version 2.0.6. --- src/files.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/files.c b/src/files.c index 2d094756..4e0f3fbf 100644 --- a/src/files.c +++ b/src/files.c @@ -2354,11 +2354,13 @@ int diralphasort(const void *va, const void *vb) if (!aisdir && bisdir) return 1; - /* Standard function brain damage: We should be sorting - * alphabetically and case-insensitively according to the current - * locale, but there's no standard strcasecoll() function, so we - * have to use multibyte strcasecmp() instead. */ - return mbstrcasecmp(a, b); + int difference = mbstrcasecmp(a, b); + + /* If two names are equivalent when ignoring case, compare them bytewise. */ + if (difference == 0) + return strcmp(a, b); + else + return difference; } #endif