From 4b3b9b792dfe2d25a271f042f23df22e8b9684f6 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 5 Mar 2010 11:28:32 +0100 Subject: QDom: prevent infinite loop when cloning a DTD we forgot to advance the pointer to the current node. Reviewed-by: Frans Englich Task-number: QTBUG-8398 --- src/xml/dom/qdom.cpp | 1 + tests/auto/qdom/tst_qdom.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 8d9ae4f..0150515 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -3487,6 +3487,7 @@ QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentTypePrivate* n, boo if (p->isNotation()) // Dont use normal insert function since we would create infinite recursion notations->map.insertMulti(p->nodeName(), p); + p = p->next; } } diff --git a/tests/auto/qdom/tst_qdom.cpp b/tests/auto/qdom/tst_qdom.cpp index d1b2ea5..caf08d6 100644 --- a/tests/auto/qdom/tst_qdom.cpp +++ b/tests/auto/qdom/tst_qdom.cpp @@ -131,6 +131,7 @@ private slots: void setContentWhitespace_data() const; void taskQTBUG4595_dontAssertWhenDocumentSpecifiesUnknownEncoding() const; + void cloneDTD_QTBUG8398() const; void cleanupTestCase() const; @@ -1912,5 +1913,29 @@ void tst_QDom::taskQTBUG4595_dontAssertWhenDocumentSpecifiesUnknownEncoding() co QVERIFY(true); } +void tst_QDom::cloneDTD_QTBUG8398() const +{ + QString dtd("\n" + "\n" + "\n" + "]>\n" + "\n"); + QDomDocument domDocument; + QVERIFY(domDocument.setContent(dtd)); + QDomDocument domDocument2 = domDocument.cloneNode(true).toDocument(); + + // for some reason, our DOM implementation reverts the order of entities + QString expected("\n" + "\n" + "\n" + "]>\n" + "\n"); + QString output; + QTextStream stream(&output); + domDocument2.save(stream, 0); + QCOMPARE(output, expected); +} QTEST_MAIN(tst_QDom) #include "tst_qdom.moc" -- cgit v0.12