Fix assertion on matchingLocales(Abhkazian, Any, Any)

CLDR v39 has no locales for Abkhazian, so the locale_index[] entry for
it actually indexes the last entry before the next language up the
enum. This has m_language_id less than Abkhazian.

Change-Id: If8b88f30476a981b3ee00ff8760a46ede0b7aab7
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Edward Welbourne 2021-05-04 10:46:17 +02:00
parent 3b155973c4
commit 358df462a0
2 changed files with 10 additions and 4 deletions

View File

@ -2640,15 +2640,15 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language, QLocale::Scr
result.reserve(locale_data_size); result.reserve(locale_data_size);
quint16 index = locale_index[language]; quint16 index = locale_index[language];
Q_ASSERT(filter.acceptLanguage(locale_data[index].m_language_id)); // There may be no matches, for some languages (e.g. Abkhazian at CLDR v39).
do { while (filter.acceptLanguage(locale_data[index].m_language_id)) {
const QLocaleId id = locale_data[index].id(); const QLocaleId id = locale_data[index].id();
if (filter.acceptScriptTerritory(id)) { if (filter.acceptScriptTerritory(id)) {
result.append(QLocale(*(id.language_id == C ? c_private() result.append(QLocale(*(id.language_id == C ? c_private()
: new QLocalePrivate(locale_data + index, index)))); : new QLocalePrivate(locale_data + index, index))));
} }
++index; ++index;
} while (filter.acceptLanguage(locale_data[index].m_language_id)); }
return result; return result;
} }

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the test suite of the Qt Toolkit. ** This file is part of the test suite of the Qt Toolkit.
@ -716,6 +716,12 @@ void tst_QLocale::matchingLocales()
QVERIFY(!locales.isEmpty()); QVERIFY(!locales.isEmpty());
QVERIFY(!locales.contains(c)); QVERIFY(!locales.contains(c));
QVERIFY(locales.contains(ru_RU)); QVERIFY(locales.contains(ru_RU));
// Regression check for assertion failure when no locales match:
locales = QLocale::matchingLocales(QLocale::Abkhazian, QLocale::AnyScript, QLocale::AnyTerritory);
// Empty in CLDR v39, but don't require that.
QVERIFY(!locales.contains(c));
QVERIFY(!locales.contains(ru_RU));
} }
void tst_QLocale::unixLocaleName_data() void tst_QLocale::unixLocaleName_data()