fixed GH #410: Bug in JSON::Object.stringify() in 1.5.2

This commit is contained in:
Alex Fabijanic 2014-04-28 21:43:57 -05:00
parent f19d1cb041
commit 4d366250e1
4 changed files with 18 additions and 8 deletions

View File

@ -54,6 +54,7 @@ Release 1.5.3 (2014-05-xx)
- added runtest script for windows
- added SQlite Full Text Search support
- added Thread::trySleep() and Thread::wakeUp()
- fixed GH #410: Bug in JSON::Object.stringify() in 1.5.2
Release 1.5.2 (2013-09-16)
==========================

View File

@ -246,7 +246,7 @@ private:
Stringifier::stringify(getValue(it), out, indent + step, step);
if ( ++it != container.end() ) out << ',';
if (++it != container.end()) out << ',';
if (step > 0) out << std::endl;
}

View File

@ -127,7 +127,7 @@ const std::string& Object::getKey(KeyPtrList::const_iterator& iter) const
ValueMap::const_iterator end = _values.end();
for (; it != end; ++it)
{
if (it->second == **iter) return it->first;
if (&it->second == *iter) return it->first;
}
throw NotFoundException((*iter)->convert<std::string>());

View File

@ -1215,12 +1215,13 @@ void JSONTest::testPrintHandler()
void JSONTest::testStringify()
{
Poco::JSON::Object obj;
obj.set("one","two");
obj.stringify(std::cout,4); //this works
obj.stringify(std::cout,1); //this never returns
std::cout << std::endl;
Object jObj(false);
jObj.set("foo", 0);
jObj.set("bar", 0);
jObj.set("baz", 0);
std::stringstream ss;
jObj.stringify(ss);
assert(ss.str() == "{\"bar\":0,\"baz\":0,\"foo\":0}");
std::string json = "{ \"Simpsons\" : { \"husband\" : { \"name\" : \"Homer\" , \"age\" : 38 }, \"wife\" : { \"name\" : \"Marge\", \"age\" : 36 }, "
"\"children\" : [ \"Bart\", \"Lisa\", \"Maggie\" ], "
@ -1348,6 +1349,14 @@ void JSONTest::testStringify()
void JSONTest::testStringifyPreserveOrder()
{
Object jObj(true);
jObj.set("foo", 0);
jObj.set("bar", 0);
jObj.set("baz", 0);
std::stringstream ss;
jObj.stringify(ss);
assert(ss.str() == "{\"foo\":0,\"bar\":0,\"baz\":0}");
std::string json = "{ \"Simpsons\" : { \"husband\" : { \"name\" : \"Homer\" , \"age\" : 38 }, \"wife\" : { \"name\" : \"Marge\", \"age\" : 36 }, "
"\"children\" : [ \"Bart\", \"Lisa\", \"Maggie\" ], "
"\"address\" : { \"number\" : 742, \"street\" : \"Evergreen Terrace\", \"town\" : \"Springfield\" } } }";