fixed GH #1521: bug in JSON ParseHandler.cpp (empty keys should be valid)

This commit is contained in:
Guenter Obiltschnig 2016-12-29 11:22:16 +01:00
parent b506a30c0d
commit ad37bc3516
3 changed files with 33 additions and 1 deletions

View File

@ -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<Object::Ptr>();
obj->set(_key, value);
_key.clear();

View File

@ -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<Object::Ptr>();
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);

View File

@ -46,6 +46,7 @@ public:
#endif
void testStringProperty();
void testEmptyObject();
void testEmptyPropertyName();
void testComplexObject();
void testDoubleProperty();
void testDouble2Property();