summaryrefslogtreecommitdiffstats
path: root/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp')
-rw-r--r--tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
index f09fbff6c4..57d078ba65 100644
--- a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
+++ b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp
@@ -160,6 +160,7 @@ class tst_QXmlSimpleReader : public QObject
void reportNamespace() const;
void reportNamespace_data() const;
void roundtripWithNamespaces() const;
+ void dtdRecursionLimit();
private:
static QDomDocument fromByteArray(const QString &title, const QByteArray &ba, bool *ok);
@@ -755,5 +756,62 @@ void tst_QXmlSimpleReader::roundtripWithNamespaces() const
}
}
+class TestHandler : public QXmlDefaultHandler
+{
+public:
+ TestHandler() :
+ recursionCount(0)
+ {
+ }
+
+ bool internalEntityDecl(const QString &name, const QString &value)
+ {
+ ++recursionCount;
+ return QXmlDefaultHandler::internalEntityDecl(name, value);
+ }
+
+ int recursionCount;
+};
+
+void tst_QXmlSimpleReader::dtdRecursionLimit()
+{
+ QFile file("xmldocs/2-levels-nested-dtd.xml");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QXmlSimpleReader xmlReader;
+ {
+ QXmlInputSource *source = new QXmlInputSource(&file);
+ TestHandler handler;
+ xmlReader.setDeclHandler(&handler);
+ xmlReader.setErrorHandler(&handler);
+ QVERIFY(!xmlReader.parse(source));
+ }
+
+ file.close();
+ file.setFileName("xmldocs/1-levels-nested-dtd.xml");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ {
+ QXmlInputSource *source = new QXmlInputSource(&file);
+ TestHandler handler;
+ xmlReader.setDeclHandler(&handler);
+ xmlReader.setErrorHandler(&handler);
+ QVERIFY(!xmlReader.parse(source));
+ // The error wasn't because of the recursion limit being reached,
+ // it was because the document is not valid.
+ QVERIFY(handler.recursionCount < 2);
+ }
+
+ file.close();
+ file.setFileName("xmldocs/internal-entity-polynomial-attribute.xml");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ {
+ QXmlInputSource *source = new QXmlInputSource(&file);
+ TestHandler handler;
+ xmlReader.setDeclHandler(&handler);
+ xmlReader.setErrorHandler(&handler);
+ QVERIFY(!xmlReader.parse(source));
+ QVERIFY(handler.recursionCount == 1);
+ }
+}
+
QTEST_MAIN(tst_QXmlSimpleReader)
#include "tst_qxmlsimplereader.moc"