diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-06-17 14:43:17 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-06-20 21:29:04 +0000 |
commit | da0d7f61c851431d14430684c62345bc23dbf001 (patch) | |
tree | 3e7bf228e48edc2ef9972806b46c83be78a585fa /tests | |
parent | 3d73aa660b5e1af5758ae7207ce1c05d7a0458e1 (diff) |
QDom: Stop treating non-BMP characters as invalid
According to https://www.w3.org/TR/REC-xml/#NT-Char unicode characters
within the range of [#x10000-#x10FFFF] are considered to be valid, so
fix the check for valid characters accordingly. This requires changing
the loop over the input QString to iterate over code points (instead of
code units).
Fixes: QTBUG-104362
Pick-to: 6.4 6.3 6.2 5.15
Change-Id: I7dcf5cad05265a54882807a50522d28b647e06ee
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/xml/dom/qdom/tst_qdom.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index e1c2b12ab5..f05020f61c 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -9,6 +9,7 @@ #include <QFile> #include <QList> #include <QRegularExpression> +#include <QScopeGuard> #include <QTextStream> #include <QTest> #include <QtXml> @@ -62,6 +63,7 @@ private slots: void invalidQualifiedName(); void invalidCharData_data(); void invalidCharData(); + void nonBMPCharacters(); void roundTripAttributes() const; void roundTripCDATA() const; @@ -1342,6 +1344,10 @@ void tst_QDom::invalidCharData_data() QTest::newRow( "f<o&o" ) << QString("f<o&o") << true << true << true << QString("f<o&o"); QTest::newRow( "empty" ) << QString() << true << true << true << QString(); QTest::newRow("f\\x07o\\x02")<< QString("f\x07o\x02")<< true << true << false << QString("fo"); + + const QChar pair[2] = { QChar(0xdc00), QChar(0xe000) }; + QString invalid(pair, 2); + QTest::newRow("\\xdc00\\xe000") << invalid << true << true << false << invalid.last(1); } void tst_QDom::invalidCharData() @@ -1385,6 +1391,22 @@ void tst_QDom::invalidCharData() } } +void tst_QDom::nonBMPCharacters() +{ + const auto invalidDataPolicy = QDomImplementation::invalidDataPolicy(); + auto resetInvalidDataPolicy = qScopeGuard( + [invalidDataPolicy] { QDomImplementation::setInvalidDataPolicy(invalidDataPolicy); }); + QDomImplementation::setInvalidDataPolicy(QDomImplementation::DropInvalidChars); + + const QString input = u"<text>Supplementary Plane: 𝄞 😂 🀄 🀶 🃪 🃋</text>"_qs; + + QString errorMsg; + QDomDocument doc; + doc.setContent(input, &errorMsg); + QVERIFY(errorMsg.isEmpty()); + QCOMPARE(doc.toString(-1), input); +} + void tst_QDom::roundTripAttributes() const { /* Create an attribute via the QDom API with weird whitespace content. */ |