Fix QStringConverter::encodingForName() for trailing -
, _
The (internal) docs say that - and _ are ignored, and they're ignored everywhere, except as suffixes. If the old code only ignored them as infixes, fine, that would make some sense, but it ignored infixes and prefixes, so there's no reason for it to not ignore suffixes, too. Fix by continuing the loop until both input ranges are exhausted, or a mismatch was found. [ChangeLog][QtCore][QStringConverter] Fixed a bug where encodingForName() failed due to trailing characters (`_`, `-`) that ought to have been ignored. Pick-to: 6.6 6.5 Change-Id: Iec21489d988eda7d33c744c170f88cd665b73f34 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
091793ccaa
commit
5f775e6719
@ -1768,21 +1768,16 @@ const QStringConverter::Interface QStringConverter::encodingInterfaces[QStringCo
|
||||
// match names case insensitive and skipping '-' and '_'
|
||||
static bool nameMatch(const char *a, const char *b)
|
||||
{
|
||||
while (*a && *b) {
|
||||
if (*a == '-' || *a == '_') {
|
||||
do {
|
||||
while (*a == '-' || *a == '_')
|
||||
++a;
|
||||
continue;
|
||||
}
|
||||
if (*b == '-' || *b == '_') {
|
||||
while (*b == '-' || *b == '_')
|
||||
++b;
|
||||
continue;
|
||||
}
|
||||
if (QtMiscUtils::toAsciiLower(*a) != QtMiscUtils::toAsciiLower(*b))
|
||||
return false;
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
return !*a && !*b;
|
||||
if (!*a && !*b) // end of both strings
|
||||
return true;
|
||||
} while (QtMiscUtils::toAsciiLower(*a++) == QtMiscUtils::toAsciiLower(*b++));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2240,6 +2240,8 @@ void tst_QStringConverter::encodingForName_data()
|
||||
row("ISO8859-1", QStringConverter::Latin1);
|
||||
row("iso8859-1", QStringConverter::Latin1);
|
||||
row("latin1", QStringConverter::Latin1);
|
||||
row("latin-1_-", QStringConverter::Latin1);
|
||||
row("latin_1-_", QStringConverter::Latin1);
|
||||
row("-_latin-1", QStringConverter::Latin1);
|
||||
row("_-latin_1", QStringConverter::Latin1);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user