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.5 Change-Id: Iec21489d988eda7d33c744c170f88cd665b73f34 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 5f775e671973b1549a48ae8c69c5db7494f6a6d3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
319089dd7f
commit
7270e2ab75
@ -1761,21 +1761,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2238,6 +2238,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