mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-25 17:28:13 +02:00
fixed GH #1521: bug in JSON ParseHandler.cpp (empty keys should be valid)
This commit is contained in:
parent
b506a30c0d
commit
ad37bc3516
@ -133,7 +133,6 @@ void ParseHandler::setValue(const Var& value)
|
|||||||
}
|
}
|
||||||
else if ( parent.type() == typeid(Object::Ptr) )
|
else if ( parent.type() == typeid(Object::Ptr) )
|
||||||
{
|
{
|
||||||
poco_assert_dbg(!_key.empty());
|
|
||||||
Object::Ptr obj = parent.extract<Object::Ptr>();
|
Object::Ptr obj = parent.extract<Object::Ptr>();
|
||||||
obj->set(_key, value);
|
obj->set(_key, value);
|
||||||
_key.clear();
|
_key.clear();
|
||||||
|
@ -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()
|
void JSONTest::testComplexObject()
|
||||||
{
|
{
|
||||||
std::string json =
|
std::string json =
|
||||||
@ -1889,6 +1920,7 @@ CppUnit::Test* JSONTest::suite()
|
|||||||
#endif
|
#endif
|
||||||
CppUnit_addTest(pSuite, JSONTest, testStringProperty);
|
CppUnit_addTest(pSuite, JSONTest, testStringProperty);
|
||||||
CppUnit_addTest(pSuite, JSONTest, testEmptyObject);
|
CppUnit_addTest(pSuite, JSONTest, testEmptyObject);
|
||||||
|
CppUnit_addTest(pSuite, JSONTest, testEmptyPropertyName);
|
||||||
CppUnit_addTest(pSuite, JSONTest, testComplexObject);
|
CppUnit_addTest(pSuite, JSONTest, testComplexObject);
|
||||||
CppUnit_addTest(pSuite, JSONTest, testDoubleProperty);
|
CppUnit_addTest(pSuite, JSONTest, testDoubleProperty);
|
||||||
CppUnit_addTest(pSuite, JSONTest, testDouble2Property);
|
CppUnit_addTest(pSuite, JSONTest, testDouble2Property);
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
void testStringProperty();
|
void testStringProperty();
|
||||||
void testEmptyObject();
|
void testEmptyObject();
|
||||||
|
void testEmptyPropertyName();
|
||||||
void testComplexObject();
|
void testComplexObject();
|
||||||
void testDoubleProperty();
|
void testDoubleProperty();
|
||||||
void testDouble2Property();
|
void testDouble2Property();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user