From a4eea312ed7b020b1bb686ec1d619b4d1f85abd4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 28 Apr 2020 15:35:58 +0200 Subject: Correctly parse non BMP char refs in the sax parser Update the auto test accordingly, and at the same time remove all uses of QTextStream (as they aren't required). Change-Id: I71b7cf6a6b54ea59507f27d5d2d04cc5ae5885fc Reviewed-by: Sona Kurazyan --- tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp | 17 +++++------------ tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp | 11 ++++++----- .../xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp | 14 ++++---------- .../sax/qxmlsimplereader/xmldocs/not-wf/sa/142.xml.ref | Bin 309 -> 311 bytes .../sax/qxmlsimplereader/xmldocs/valid/sa/064.xml.ref | Bin 312 -> 316 bytes .../sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.ref | Bin 381 -> 378 bytes 6 files changed, 15 insertions(+), 27 deletions(-) (limited to 'tests/auto/xml/sax') diff --git a/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp b/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp index b5d9fea315..c5597c6f8e 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/parser/main.cpp @@ -37,7 +37,6 @@ #include "parser.h" -static QTextStream qout(stdout, QIODevice::WriteOnly); static QTextStream qerr(stderr, QIODevice::WriteOnly); static void usage() @@ -79,19 +78,15 @@ int main(int argc, const char *argv[]) if (out_file_name.isEmpty()) out_file_name = file_name + ".ref"; - QFile _out_file; - QTextStream _out_stream; - QTextStream *out_stream; + QFile out_file; if (out_file_name == "-") { - out_stream = &qout; + out_file.open(stdout, QFile::WriteOnly); } else { - _out_file.setFileName(out_file_name); - if (!_out_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + out_file.setFileName(out_file_name); + if (!out_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { qerr << "Could not open " << out_file_name << ": " << strerror(errno) << Qt::endl; return 1; } - _out_stream.setDevice(&_out_file); - out_stream = &_out_stream; } Parser parser; @@ -102,9 +97,7 @@ int main(int argc, const char *argv[]) parser.parseFile(&in_file); - out_stream->setCodec("utf8"); - - *out_stream << parser.result(); + out_file.write(parser.result().toUtf8()); return 0; } diff --git a/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp b/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp index 44f8101955..24aa9376da 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp @@ -142,11 +142,12 @@ bool ContentHandler::startElement(const QString &namespaceURI, QString ContentHandler::escapeStr(const QString &s) { QString result = s; - result.replace(QRegularExpression("\""), "\\\""); - result.replace(QRegularExpression("\\"), "\\\\"); - result.replace(QRegularExpression("\n"), "\\n"); - result.replace(QRegularExpression("\r"), "\\r"); - result.replace(QRegularExpression("\t"), "\\t"); + result.replace(QChar(0), "\\0"); + result.replace("\\", "\\\\"); + result.replace("\"", "\\\""); + result.replace("\n", "\\n"); + result.replace("\r", "\\r"); + result.replace("\t", "\\t"); return result; } diff --git a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp index cea4e3c8b8..df158cae0f 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp @@ -311,14 +311,12 @@ void tst_QXmlSimpleReader::testGoodXmlFile() QVERIFY(file.open(QIODevice::ReadOnly)); Parser parser; - QEXPECT_FAIL(QFINDTESTDATA("xmldocs/valid/sa/089.xml").toLocal8Bit().constData(), "a form feed character is not accepted in XML", Continue); QVERIFY(parser.parseFile(&file)); QFile ref_file(file_name + ".ref"); QVERIFY(ref_file.open(QIODevice::ReadOnly | QIODevice::Text)); - QTextStream ref_stream(&ref_file); - ref_stream.setCodec("UTF-8"); - QString ref_file_contents = ref_stream.readAll(); + QByteArray data = ref_file.readAll(); + QString ref_file_contents = QString::fromUtf8(data.constData(), data.size()); QCOMPARE(parser.result(), ref_file_contents); } @@ -393,9 +391,7 @@ void tst_QXmlSimpleReader::testBadXmlFile() QFile ref_file(file_name + ".ref"); QVERIFY(ref_file.open(QIODevice::ReadOnly | QIODevice::Text)); - QTextStream ref_stream(&ref_file); - ref_stream.setCodec("UTF-8"); - QString ref_file_contents = ref_stream.readAll(); + QString ref_file_contents = QString::fromUtf8(ref_file.readAll()); QEXPECT_FAIL(QFINDTESTDATA("xmldocs/not-wf/sa/145.xml").toLocal8Bit().constData(), "Surrogate code point 0xD800 should be rejected", Continue); @@ -469,9 +465,7 @@ void tst_QXmlSimpleReader::testIncrementalParsing() QFile ref_file(file_name + ".ref"); QVERIFY(ref_file.open(QIODevice::ReadOnly | QIODevice::Text)); - QTextStream ref_stream(&ref_file); - ref_stream.setCodec("UTF-8"); - QString ref_file_contents = ref_stream.readAll(); + QString ref_file_contents = QString::fromUtf8(ref_file.readAll()); QCOMPARE(parser.result(), ref_file_contents); } diff --git a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/not-wf/sa/142.xml.ref b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/not-wf/sa/142.xml.ref index 7ce4da6a06..0684cfa943 100644 Binary files a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/not-wf/sa/142.xml.ref and b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/not-wf/sa/142.xml.ref differ diff --git a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/064.xml.ref b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/064.xml.ref index 579aeb52f6..0b806c96a8 100644 Binary files a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/064.xml.ref and b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/064.xml.ref differ diff --git a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.ref b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.ref index 7c68c32286..f09bc2bd09 100644 Binary files a/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.ref and b/tests/auto/xml/sax/qxmlsimplereader/xmldocs/valid/sa/089.xml.ref differ -- cgit v1.2.3