summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Adams <chris.adams@qinetic.com.au>2018-10-31 17:37:04 +1000
committerChristopher Adams <chris.adams@jollamobile.com>2018-11-08 00:20:49 +0000
commitcba196735e9c89d1bbe2230493b43b92f1596c4b (patch)
tree1be1a68282183067ea9338937eb9a1f0f8048c34
parent189bc66734adf753b24b8b175125afb401eaa835 (diff)
Work around malformed Versit documents with empty interior lines
If a Versit document is encountered which has empty lines in between two property definitions, we should ignore the empty lines and continue parsing the document. Change-Id: Ic1165f056dd040d26d3b40e26a47c16f8e173e3f Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au>
-rw-r--r--src/versit/qversitreader_p.cpp4
-rw-r--r--tests/auto/versit/qversitreader/tst_qversitreader.cpp18
2 files changed, 22 insertions, 0 deletions
diff --git a/src/versit/qversitreader_p.cpp b/src/versit/qversitreader_p.cpp
index e013810ba..7ddf2c601 100644
--- a/src/versit/qversitreader_p.cpp
+++ b/src/versit/qversitreader_p.cpp
@@ -643,6 +643,10 @@ bool QVersitReaderPrivate::parseVersitDocumentBody(LineReader* lineReader, QVers
while (true) {
/* Grab it */
QVersitProperty property = parseNextVersitProperty(document->type(), lineReader);
+ while (property.isEmpty() && !lineReader->atEnd()) {
+ // Work around malformed documents by ignoring empty interior lines
+ property = parseNextVersitProperty(document->type(), lineReader);
+ }
if (property.name() == QStringLiteral("BEGIN")) {
// Nested Versit document
diff --git a/tests/auto/versit/qversitreader/tst_qversitreader.cpp b/tests/auto/versit/qversitreader/tst_qversitreader.cpp
index 1585db7d4..7d4bdaf43 100644
--- a/tests/auto/versit/qversitreader/tst_qversitreader.cpp
+++ b/tests/auto/versit/qversitreader/tst_qversitreader.cpp
@@ -397,6 +397,24 @@ void tst_QVersitReader::testReading()
QCOMPARE(mReader->error(), QVersitReader::NoError);
QCOMPARE(results.count(),1);
+ // Exception case for two properties separated by CrLfCrLf
+ const QByteArray emptyInteriorLinesTest =
+ "BEGIN:VCARD\r\n"
+ "VERSION:4.0\r\n"
+ "FN:John\r\n"
+ "\r\n\r\n"
+ "EMAIL;ENCODING=QUOTED-PRINTABLE:john.citizen@example.com\r\n"
+ "END:VCARD\r\n";
+ mInputDevice->close();
+ mInputDevice->setData(emptyInteriorLinesTest);
+ mInputDevice->open(QBuffer::ReadOnly);
+ mInputDevice->seek(0);
+ QVERIFY2(mReader->startReading(), QString::number(mReader->error()).toLatin1().data());
+ QVERIFY2(mReader->waitForFinished(), QString::number(mReader->error()).toLatin1().data());
+ results = mReader->results();
+ QCOMPARE(mReader->state(), QVersitReader::FinishedState);
+ QCOMPARE(mReader->error(), QVersitReader::NoError);
+ QCOMPARE(results.count(), 1);
// vCard 4.0
const QByteArray& vcard40 =