diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-02-05 15:42:41 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-02-14 19:13:37 +0100 |
commit | 1c0b69eac521fec074390c023be8b5a23e88dd50 (patch) | |
tree | 525c90029eac4617b1a01c8eef15fff5b411c289 | |
parent | 81bd1bba7b67716ed0ae565061ebedc5a5455a40 (diff) |
Only read the first BOM as a BOM; the rest are ZWNBS !
QUtf32::convertToUnicode() was forgetting to set headerdone when it
dealt with the header (for contrast, Utf16::convertToUnicode() does).
Fixes: QTBUG-62011
Change-Id: Ia254782ce0967a6cf9ce0e81eb06d41521150eed
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/codecs/qutfcodec.cpp | 1 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp index af36bd7e2f..8561f908b9 100644 --- a/src/corelib/codecs/qutfcodec.cpp +++ b/src/corelib/codecs/qutfcodec.cpp @@ -930,6 +930,7 @@ QString QUtf32::convertToUnicode(const char *chars, int len, QTextCodec::Convert tuple[num++] = *chars++; if (num == 4) { if (!headerdone) { + headerdone = true; if (endian == DetectEndianness) { if (tuple[0] == 0xff && tuple[1] == 0xfe && tuple[2] == 0 && tuple[3] == 0 && endian != BigEndianness) { endian = LittleEndianness; diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 7ea93a87d6..3714e854f7 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -4704,6 +4704,12 @@ void tst_QString::fromUcs4() s = QString::fromUcs4(U"\u221212\U000020AC\U00010000"); QCOMPARE(s, QString::fromUtf8("\342\210\222" "12" "\342\202\254" "\360\220\200\200")); #endif + + // QTBUG-62011: don't mistake ZWNBS for BOM + // Start with one BOM, to ensure we use the right endianness: + const uint text[] = { 0xfeff, 97, 0xfeff, 98, 0xfeff, 99, 0xfeff, 100 }; + s = QString::fromUcs4(text, 8); + QCOMPARE(s, QStringView(u"a\xfeff" u"b\xfeff" u"c\xfeff" "d")); } void tst_QString::toUcs4() |