summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/json
diff options
context:
space:
mode:
authorAlexei Rousskikh <ext-alexei.rousskikh@nokia.com>2012-03-12 14:33:39 -0400
committerQt by Nokia <qt-info@nokia.com>2012-03-12 21:38:51 +0100
commit612040a0cd702e4c764e5cbb5d0c091497650c6a (patch)
treea47186f97ae77e71495c4e6b3765a2d9d5236491 /tests/auto/corelib/json
parent0353430806fb14b438cf7d68c68d8cdbcb57ef45 (diff)
Trailing comma should result in an error during JSON parsing
1. QJsonParseError::MissingObject defined 2. QJsonDocument::fromJson() will result in defined error after parsing of something like "{ 'key':1 , }" or "[ {'key':1}, ]" Change-Id: I8e6234a03b8aca4e5ad6180f273f91066b86d7a1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/corelib/json')
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index 079ff6e76b..87820d2e78 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -120,6 +120,8 @@ private Q_SLOTS:
void assignObjects();
void assignArrays();
+
+ void testTrailingComma();
private:
QString testDataDir;
};
@@ -1807,5 +1809,16 @@ void TestQtJson::assignArrays()
QCOMPARE(inner.at(0).toDouble(), 2.);
}
+void TestQtJson::testTrailingComma()
+{
+ const char *jsons[] = { "{ \"Key\": 1, }", "[ { \"Key\": 1 }, ]" };
+
+ for (unsigned i = 0; i < sizeof(jsons)/sizeof(jsons[0]); ++i) {
+ QJsonParseError error;
+ QJsonDocument doc = QJsonDocument::fromJson(jsons[i], &error);
+ QCOMPARE(error.error, QJsonParseError::MissingObject);
+ }
+}
+
QTEST_MAIN(TestQtJson)
#include "tst_qtjson.moc"