From 25d807f6292e9918ccdbe06cf7f590f60ecae457 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 29 Oct 2021 12:36:19 +0200 Subject: [PATCH] Correct qcollator_posix.cpp's check against system locale The check was made against the default locale but the code calls the system functions (wcscoll, wcsxfrm, wcscmp) for locale-specific collation, so should be comparing to the system locale's collation locale (i.e. LC_COLLATE). Also correct the Android-only check in tst_QCollator::compare() which duplicated the check but neglected the C locale, which is also supported (via QString::compare). Pick-to: 6.2 Change-Id: I48c3237dd6825e2070272ab88d95bdb8cbb9fc37 Reviewed-by: Aleix Pol Gonzalez Reviewed-by: Thiago Macieira --- src/corelib/text/qcollator_posix.cpp | 9 ++++++--- tests/auto/corelib/text/qcollator/tst_qcollator.cpp | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qcollator_posix.cpp b/src/corelib/text/qcollator_posix.cpp index 92148fa3154..7f048474346 100644 --- a/src/corelib/text/qcollator_posix.cpp +++ b/src/corelib/text/qcollator_posix.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2020 Aleix Pol Gonzalez +** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2013 Aleix Pol Gonzalez ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -49,8 +50,10 @@ QT_BEGIN_NAMESPACE void QCollatorPrivate::init() { if (!isC()) { - if (locale != QLocale()) - qWarning("Only C and default locale supported with the posix collation implementation"); + if (locale != QLocale::system().collation()) { + qWarning("Only the C and system collation locales are supported " + "with the POSIX collation implementation"); + } if (caseSensitivity != Qt::CaseSensitive) qWarning("Case insensitive sorting unsupported in the posix collation implementation"); } diff --git a/tests/auto/corelib/text/qcollator/tst_qcollator.cpp b/tests/auto/corelib/text/qcollator/tst_qcollator.cpp index 4935ba9cf2a..ce1844f345e 100644 --- a/tests/auto/corelib/text/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/text/qcollator/tst_qcollator.cpp @@ -282,8 +282,8 @@ void tst_QCollator::compare() }; #ifdef Q_OS_ANDROID - if (collator.locale() != QLocale()) - QSKIP("Posix implementation of collation only supports default locale"); + if (collator.locale() != QLocale::c() && collator.locale() != QLocale::system().collation()) + QSKIP("POSIX implementation of collation only supports C and system collation locales"); #endif if (numericMode)