From 08775e4bd745276bcc6a5a9fdc4bed7aca225112 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 Jan 2016 16:10:00 +0100 Subject: Revert "QString: preserve embedded NULs when converting from QByteArray" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This partially reverts commit e486d69133178ccce7c75cf48201ab28efb20e44. It broke too many users, even though all of them deserved to be broken. The new functionality will be provided by differently-named functions, where possible (problem: equality operators). I did not revert the fix for the off-by-one error in tst_qtextdocumentfragment.cpp. I also didn't revert the change in the inequality relational operators, since for all strings s1, s2 and s2' where s2' is s2 truncated at the first NUL, s1 < s2 ⟺ s1 < s2' (since NUL < c for any c != 0), and, trivially, for ≤, >, ≥, too. This does not hold for = and ≠, of course, since "foo\0bar" ≠ "foo". [ChangeLog][Important Behavior Changes][EDITORIAL] Reverted: All conversions from QByteArray to QString now preserve embedded NULs... Change-Id: If4b47048b39ae5be6ed08e6d91809626a67ea7f5 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 39 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (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 907dcf17e1..a922e3ad27 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1148,7 +1148,7 @@ void tst_QString::constructorQByteArray_data() ba1[5] = 'e'; ba1[6] = 'f'; - QTest::newRow( "2" ) << ba1 << QStringLiteral("abc\0def"); + QTest::newRow( "2" ) << ba1 << QString("abc"); QTest::newRow( "3" ) << QByteArray::fromRawData("abcd", 3) << QString("abc"); QTest::newRow( "4" ) << QByteArray("\xc3\xa9") << QString("\xc3\xa9"); @@ -1169,6 +1169,12 @@ void tst_QString::constructorQByteArray() QCOMPARE( strBA, expected ); // test operator= too + if (src.constData()[src.length()] == '\0') { + str1.clear(); + str1 = src.constData(); + QCOMPARE( str1, expected ); + } + strBA.clear(); strBA = src; QCOMPARE( strBA, expected ); @@ -2569,6 +2575,14 @@ void tst_QString::append_bytearray_special_cases() QTEST( str, "res" ); } + + QFETCH( QByteArray, ba ); + if (ba.constData()[ba.length()] == '\0') { + QFETCH( QString, str ); + + str.append(ba.constData()); + QTEST( str, "res" ); + } } void tst_QString::operator_pluseq_data(bool emptyIsNoop) @@ -2599,6 +2613,14 @@ void tst_QString::operator_pluseq_bytearray_special_cases() QTEST( str, "res" ); } + + QFETCH( QByteArray, ba ); + if (ba.constData()[ba.length()] == '\0') { + QFETCH( QString, str ); + + str += ba.constData(); + QTEST( str, "res" ); + } } void tst_QString::operator_eqeq_bytearray_data() @@ -2613,6 +2635,11 @@ void tst_QString::operator_eqeq_bytearray() QVERIFY(expected == src); QVERIFY(!(expected != src)); + + if (src.constData()[src.length()] == '\0') { + QVERIFY(expected == src.constData()); + QVERIFY(!(expected != src.constData())); + } } void tst_QString::swap() @@ -2670,7 +2697,7 @@ void tst_QString::prepend_bytearray_special_cases_data() // byte array with only a 0 ba.resize( 1 ); ba[0] = 0; - QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QStringLiteral("\0foobar "); + QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QString("foobar "); // empty byte array ba.resize( 0 ); @@ -2700,6 +2727,14 @@ void tst_QString::prepend_bytearray_special_cases() QTEST( str, "res" ); } + + QFETCH( QByteArray, ba ); + if (ba.constData()[ba.length()] == '\0') { + QFETCH( QString, str ); + + str.prepend(ba.constData()); + QTEST( str, "res" ); + } } void tst_QString::replace_uint_uint() -- cgit v1.2.3