1
0
Fork 0

Fix bb8a0c7641: Strip control codes before sorting NewGRF names. (#13034)

Now that SkipGarbage doesn't skip all multi-byte utf-8 characters, string control codes are not skipped either. This gave unintended sorting when NewGRF names start with colour codes.

Use StrMakeValid() before comparing. This has to make a copy of the string for each sort step, so there is likely a performance penalty.
pull/13342/head
Peter Nelson 2025-01-19 21:39:44 +00:00 committed by GitHub
parent 40a29a71fb
commit 65665ccb78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -1445,7 +1445,9 @@ private:
/** Sort grfs by name. */
static bool NameSorter(const GRFConfig * const &a, const GRFConfig * const &b)
{
int i = StrNaturalCompare(a->GetName(), b->GetName(), true); // Sort by name (natural sorting).
std::string name_a = StrMakeValid(a->GetName(), SVS_NONE); // Make a copy without control codes.
std::string name_b = StrMakeValid(b->GetName(), SVS_NONE); // Make a copy without control codes.
int i = StrNaturalCompare(name_a, name_b, true); // Sort by name (natural sorting).
if (i != 0) return i < 0;
i = a->version - b->version;