From 612040a0cd702e4c764e5cbb5d0c091497650c6a Mon Sep 17 00:00:00 2001 From: Alexei Rousskikh Date: Mon, 12 Mar 2012 14:33:39 -0400 Subject: 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 --- tests/auto/corelib/json/tst_qtjson.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto') 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" -- cgit v1.2.3