From ea6675374fa6e94bd4cf10613c85cee2c724bcdc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 23 Jan 2018 10:25:54 -0800 Subject: QString: fix comparisons to null strings in ucstricmp Commit 8f52ad9fe084eee26869e4a94a678076845a6f58 ("ucstricmp: compare null and empty strings equal") made sure empties and nulls would compare equally, but may have broken the null vs non-empty comparison (which was not tested). The commit message also said that it expected all callers to handle null before calling into those functions, but that's not the case for QStringView created from a null QString: the incoming "a" pointer was null. So just remove the checks for null pointers and rely on the size checks doing the right thing. [ChangeLog][QtCore][QString] Fixed a regression from 5.9 that caused comparing default-constructed QStrings to be sorted after non-empty strings. Task-number: QTBUG-65939 Change-Id: I56b444f9d6274221a3b7fffd150c83ad46c599b6 Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/tools/qstring/tst_qstring.cpp') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 70ccc72630..a028391b06 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -6043,8 +6043,14 @@ void tst_QString::compare_data() QTest::addColumn("csr"); // case sensitive result QTest::addColumn("cir"); // case insensitive result - // null strings + QTest::newRow("null-null") << QString() << QString() << 0 << 0; + QTest::newRow("text-null") << QString("a") << QString() << 1 << 1; + QTest::newRow("null-text") << QString() << QString("a") << -1 << -1; + QTest::newRow("null-empty") << QString() << QString("") << 0 << 0; + QTest::newRow("empty-null") << QString("") << QString() << 0 << 0; + + // empty strings QTest::newRow("data0") << QString("") << QString("") << 0 << 0; QTest::newRow("data1") << QString("a") << QString("") << 1 << 1; QTest::newRow("data2") << QString("") << QString("a") << -1 << -1; -- cgit v1.2.3