Fix assertion failure in QLocale::uiLanguages()
If an entry in the list from the system query exercises a legacy tag, the QLocaleId it gets converted to has a name() that's different from it. The check that this name matches the list item that it's derived from was consequently failing. Have that check fall back to actually doing the round-trip via parsing to compare the name, if the (still cheaper, so retained) naive check fails. Fixes: QTBUG-131127 Change-Id: Ifa004deff880109031ff56be00bebff6f5106e62 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
454f010e58
commit
adfa4cafdb
@ -5036,8 +5036,10 @@ QStringList QLocale::uiLanguages(TagSeparator separator) const
|
||||
const auto prior = QString::fromLatin1(id.name(sep));
|
||||
if (isSystem && i < uiLanguages.size()) {
|
||||
// Adding likely-adjusted forms to system locale's list.
|
||||
Q_ASSERT(uiLanguages.at(i) == prior
|
||||
// A legacy code may get mapped to an ID with a different name:
|
||||
|| QLatin1String(QLocaleId::fromName(uiLanguages.at(i)).name(sep)) == prior);
|
||||
// Insert just after the entry we're supplementing:
|
||||
Q_ASSERT(uiLanguages.at(i) == prior);
|
||||
j = i + 1;
|
||||
} else {
|
||||
// Plain locale or empty system uiLanguages; just append.
|
||||
|
@ -4090,6 +4090,10 @@ public:
|
||||
return QVariant(QStringList{u"en-CA"_s, u"fr-CA"_s, u"de-AT"_s,
|
||||
u"en-GB"_s, u"fr-FR"_s});
|
||||
}
|
||||
if (m_name == u"no") // QTBUG-131127
|
||||
return QVariant(QStringList{u"no"_s, u"en-US"_s, u"nb"_s});
|
||||
if (m_name == u"no-US") // Empty query result:
|
||||
return QVariant(QStringList{});
|
||||
return QVariant(QStringList{m_name});
|
||||
case LanguageId:
|
||||
return m_id.language_id;
|
||||
@ -4122,6 +4126,15 @@ void tst_QLocale::mySystemLocale_data()
|
||||
QTest::addColumn<QLocale::Language>("language");
|
||||
QTest::addColumn<QStringList>("uiLanguages");
|
||||
|
||||
QTest::addRow("empty")
|
||||
<< u"no-US"_s << QLocale::NorwegianBokmal
|
||||
<< QStringList{u"nb-US"_s, u"nb-Latn-US"_s,
|
||||
u"nb-Latn-NO"_s, u"nb-NO"_s, u"nb"_s, u"nb-Latn"_s};
|
||||
QTest::addRow("no") // QTBUG-131127
|
||||
<< u"no"_s << QLocale::NorwegianBokmal
|
||||
<< QStringList{u"no"_s, u"nb-Latn-NO"_s, u"nb-NO"_s, u"en-US"_s, u"en-Latn-US"_s, u"en"_s,
|
||||
u"nb"_s, u"nb-Latn-NO"_s, u"nb-NO"_s, u"nb-Latn"_s, u"en-Latn"_s};
|
||||
|
||||
QTest::addRow("catalan")
|
||||
<< u"ca"_s << QLocale::Catalan
|
||||
<< QStringList{u"ca"_s, u"ca-Latn-ES"_s, u"ca-ES"_s, u"ca-Latn"_s};
|
||||
|
Loading…
x
Reference in New Issue
Block a user