diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp
index aa499616d7..459a2b5311 100644
--- a/src/xml/dom/qdomhelpers.cpp
+++ b/src/xml/dom/qdomhelpers.cpp
@@ -364,7 +364,7 @@ bool QDomParser::parseBody()
break;
case QXmlStreamReader::Characters:
if (!reader->isWhitespace()) { // Skip the content consisting of only whitespaces
- if (!reader->text().trimmed().isEmpty()) {
+ if (reader->isCDATA() || !reader->text().trimmed().isEmpty()) {
if (!domBuilder.characters(reader->text().toString(), reader->isCDATA())) {
domBuilder.fatalError(QDomParser::tr(
"Error occurred while processing the element content"));
diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp
index b1c9b2e9c9..cc0eef3d02 100644
--- a/tests/auto/xml/dom/qdom/tst_qdom.cpp
+++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp
@@ -87,6 +87,7 @@ private slots:
void invalidCharData();
void roundTripAttributes() const;
+ void roundTripCDATA() const;
void normalizeEndOfLine() const;
void normalizeAttributes() const;
void serializeWeirdEOL() const;
@@ -1441,6 +1442,17 @@ void tst_QDom::roundTripAttributes() const
QCOMPARE(QString::fromLatin1(serialized.constData()), QString::fromLatin1(expected.constData()));
}
+void tst_QDom::roundTripCDATA() const
+{
+ const QString input = u"\n"
+ "\n"_qs;
+ QString errorMsg;
+ QDomDocument doc;
+ QVERIFY(doc.setContent(input, false, &errorMsg));
+ QVERIFY(errorMsg.isEmpty());
+ QCOMPARE(doc.toString(), input);
+}
+
void tst_QDom::normalizeEndOfLine() const
{
QByteArray input("\r\nc\rc\ra\na");