From ad37bc3516df23c655b5fb7be89c7ab45d120903 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Thu, 29 Dec 2016 11:22:16 +0100 Subject: [PATCH] fixed GH #1521: bug in JSON ParseHandler.cpp (empty keys should be valid) --- JSON/src/ParseHandler.cpp | 1 - JSON/testsuite/src/JSONTest.cpp | 32 ++++++++++++++++++++++++++++++++ JSON/testsuite/src/JSONTest.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/JSON/src/ParseHandler.cpp b/JSON/src/ParseHandler.cpp index 74296493a..30c8ece07 100644 --- a/JSON/src/ParseHandler.cpp +++ b/JSON/src/ParseHandler.cpp @@ -133,7 +133,6 @@ void ParseHandler::setValue(const Var& value) } else if ( parent.type() == typeid(Object::Ptr) ) { - poco_assert_dbg(!_key.empty()); Object::Ptr obj = parent.extract(); obj->set(_key, value); _key.clear(); diff --git a/JSON/testsuite/src/JSONTest.cpp b/JSON/testsuite/src/JSONTest.cpp index d248bdc1e..99dfe9d25 100644 --- a/JSON/testsuite/src/JSONTest.cpp +++ b/JSON/testsuite/src/JSONTest.cpp @@ -377,6 +377,37 @@ void JSONTest::testEmptyObject() } +void JSONTest::testEmptyPropertyName() +{ + std::string json = "{\"\": 42}"; + Parser parser; + Var result; + + try + { + result = parser.parse(json); + } + catch(JSONException& jsone) + { + std::cout << jsone.message() << std::endl; + assert(false); + } + + assert(result.type() == typeid(Object::Ptr)); + + Object::Ptr object = result.extract(); + assert(object->size() == 1); + + DynamicStruct ds = *object; + assert (ds.size() == 1); + + const DynamicStruct& rds = *object; + assert (rds.size() == 1); + + assert (ds[""] == 42); +} + + void JSONTest::testComplexObject() { std::string json = @@ -1889,6 +1920,7 @@ CppUnit::Test* JSONTest::suite() #endif CppUnit_addTest(pSuite, JSONTest, testStringProperty); CppUnit_addTest(pSuite, JSONTest, testEmptyObject); + CppUnit_addTest(pSuite, JSONTest, testEmptyPropertyName); CppUnit_addTest(pSuite, JSONTest, testComplexObject); CppUnit_addTest(pSuite, JSONTest, testDoubleProperty); CppUnit_addTest(pSuite, JSONTest, testDouble2Property); diff --git a/JSON/testsuite/src/JSONTest.h b/JSON/testsuite/src/JSONTest.h index 637de2e50..be9e25538 100644 --- a/JSON/testsuite/src/JSONTest.h +++ b/JSON/testsuite/src/JSONTest.h @@ -46,6 +46,7 @@ public: #endif void testStringProperty(); void testEmptyObject(); + void testEmptyPropertyName(); void testComplexObject(); void testDoubleProperty(); void testDouble2Property();