From a5febadac55741b4b48f25463a310835cc8bde19 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 28 Jan 2017 09:30:14 +0100 Subject: QString(Ref): make toLatin1()/toLocal8Bit() null handling consistent Systematic testing in tst_QStringApiSymmetry revealed a bug in QStringRef::toLatin1(): a null input did not result in a null output, but an empty one. This is fixed, for consistency with QString::toLatin1(), and QString(Ref)::toUtf8(), which behaved correctly already. The same bug was found in QString(Ref)::toLocal8Bit(), which is particularly hideous, as it's documented to fall back to toLatin1(), which preserves null inputs. Fixed, too. [ChangeLog][QtCore][QString] toLocal8Bit() now preserves nullness of the input QString (outputs null QByteArray). [ChangeLog][QtCore][QStringRef] toLocal8Bit() and toLatin1() now preserve nullness of the input QStringRef (output null QByteArrays). Change-Id: I7026211922c287e03d07e89edbad2987aa646e51 Reviewed-by: Edward Welbourne --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 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 727eda7456..48e856f406 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -4273,11 +4273,7 @@ void tst_QString::local8Bit_data() QTest::addColumn("local8Bit"); QTest::addColumn("result"); -/* - QString::local8Bit() called on a null QString returns an _empty_ - QByteArray. -*/ - QTest::newRow("nullString") << QString() << QByteArray(""); + QTest::newRow("nullString") << QString() << QByteArray(); QTest::newRow("emptyString") << QString("") << QByteArray(""); QTest::newRow("string") << QString("test") << QByteArray("test"); -- cgit v1.2.3