diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 1a5c9f6766..1cedd3a28d 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1065,8 +1065,10 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCo } } } + if (!c) + c = defaultCodec; - return defaultCodec; + return c; } /*! diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index b5f736cfbb..616fe33309 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -1917,6 +1917,17 @@ void tst_QTextCodec::codecForHtml_data() html = "Test"; QTest::newRow("invalid charset, early terminator (')") << html << noDefault << fallback; + + const char src[] = { char(0xff), char(0xfe), char(0x7a), char(0x03), 0, 0 }; + html = src; + QTest::newRow("greek text UTF-16LE") << html << 106 << 1014; + + html = "ͻ\000"; + QTest::newRow("greek text UTF-8") << html << 106 << 106; } void tst_QTextCodec::codecForHtml()