summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/xml/dom/qdomhelpers.cpp2
-rw-r--r--tests/auto/xml/dom/qdom/tst_qdom.cpp12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp
index aa499616d7f..459a2b5311c 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 b1c9b2e9c9e..cc0eef3d02f 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"<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<content><![CDATA[]]></content>\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("<a>\r\nc\rc\ra\na</a>");