From e96a311334a5c70d5ffcc2ca5c10919952b99636 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 8 Sep 2020 14:59:05 +0200 Subject: Use UTF-8 when converting 8 bit data in QTextStream This was overlooked when doing the conversion to use UTF-8 as the standard 8 bit encoding for text. Fixes: QTBUG-54942 Change-Id: Ib7b1b75b4d694648ab7143f6930b6bb1dcad19c9 Reviewed-by: Thiago Macieira --- .../auto/corelib/serialization/qtextstream/tst_qtextstream.cpp | 4 ++-- tests/auto/corelib/text/qstring/tst_qstring.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index e1fd7a7147..f9de9eeebf 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -2125,9 +2125,9 @@ void tst_QTextStream::generateStringData(bool for_QString) if (!for_QString) { QTest::newRow("utf16-BE (empty)") << QByteArray("\xff\xfe", 2) << QByteArray() << QString(); - QTest::newRow("utf16-BE (corrupt)") << QByteArray("\xff", 1) << QByteArray("\xff") << QString::fromLatin1("\xff"); + QTest::newRow("utf16-BE (corrupt)") << QByteArray("\xff", 1) << QByteArray("\xc3\xbf") << QString::fromUtf8("\xc3\xbf"); QTest::newRow("utf16-LE (empty)") << QByteArray("\xfe\xff", 2) << QByteArray() << QString(); - QTest::newRow("utf16-LE (corrupt)") << QByteArray("\xfe", 1) << QByteArray("\xfe") << QString::fromLatin1("\xfe"); + QTest::newRow("utf16-LE (corrupt)") << QByteArray("\xfe", 1) << QByteArray("\xc3\xbe") << QString::fromUtf8("\xc3\xbe"); } } diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 8f77d03226..6e1b47a839 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3963,8 +3963,16 @@ void tst_QString::check_QTextIOStream() { a=""; QTextStream ts(&a); + // invalid Utf8 ts << "pi \261= " << 3.125; - QCOMPARE(a, QString::fromLatin1("pi \261= 3.125")); + QCOMPARE(a, QString::fromUtf16(u"pi \xfffd= 3.125")); + } + { + a=""; + QTextStream ts(&a); + // valid Utf8 + ts << "pi ø= " << 3.125; + QCOMPARE(a, QString::fromUtf16(u"pi ø= 3.125")); } { a="123 456"; -- cgit v1.2.3