Skip to content

Commit 4d36625

Browse files
committed
fixed GH pocoproject#410: Bug in JSON::Object.stringify() in 1.5.2
1 parent f19d1cb commit 4d36625

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Release 1.5.3 (2014-05-xx)
5454
- added runtest script for windows
5555
- added SQlite Full Text Search support
5656
- added Thread::trySleep() and Thread::wakeUp()
57+
- fixed GH #410: Bug in JSON::Object.stringify() in 1.5.2
5758

5859
Release 1.5.2 (2013-09-16)
5960
==========================

JSON/include/Poco/JSON/Object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class JSON_API Object
246246

247247
Stringifier::stringify(getValue(it), out, indent + step, step);
248248

249-
if ( ++it != container.end() ) out << ',';
249+
if (++it != container.end()) out << ',';
250250

251251
if (step > 0) out << std::endl;
252252
}

JSON/src/Object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const std::string& Object::getKey(KeyPtrList::const_iterator& iter) const
127127
ValueMap::const_iterator end = _values.end();
128128
for (; it != end; ++it)
129129
{
130-
if (it->second == **iter) return it->first;
130+
if (&it->second == *iter) return it->first;
131131
}
132132

133133
throw NotFoundException((*iter)->convert<std::string>());

JSON/testsuite/src/JSONTest.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,12 +1215,13 @@ void JSONTest::testPrintHandler()
12151215

12161216
void JSONTest::testStringify()
12171217
{
1218-
Poco::JSON::Object obj;
1219-
obj.set("one","two");
1220-
obj.stringify(std::cout,4); //this works
1221-
obj.stringify(std::cout,1); //this never returns
1222-
std::cout << std::endl;
1223-
1218+
Object jObj(false);
1219+
jObj.set("foo", 0);
1220+
jObj.set("bar", 0);
1221+
jObj.set("baz", 0);
1222+
std::stringstream ss;
1223+
jObj.stringify(ss);
1224+
assert(ss.str() == "{\"bar\":0,\"baz\":0,\"foo\":0}");
12241225

12251226
std::string json = "{ \"Simpsons\" : { \"husband\" : { \"name\" : \"Homer\" , \"age\" : 38 }, \"wife\" : { \"name\" : \"Marge\", \"age\" : 36 }, "
12261227
"\"children\" : [ \"Bart\", \"Lisa\", \"Maggie\" ], "
@@ -1348,6 +1349,14 @@ void JSONTest::testStringify()
13481349

13491350
void JSONTest::testStringifyPreserveOrder()
13501351
{
1352+
Object jObj(true);
1353+
jObj.set("foo", 0);
1354+
jObj.set("bar", 0);
1355+
jObj.set("baz", 0);
1356+
std::stringstream ss;
1357+
jObj.stringify(ss);
1358+
assert(ss.str() == "{\"foo\":0,\"bar\":0,\"baz\":0}");
1359+
13511360
std::string json = "{ \"Simpsons\" : { \"husband\" : { \"name\" : \"Homer\" , \"age\" : 38 }, \"wife\" : { \"name\" : \"Marge\", \"age\" : 36 }, "
13521361
"\"children\" : [ \"Bart\", \"Lisa\", \"Maggie\" ], "
13531362
"\"address\" : { \"number\" : 742, \"street\" : \"Evergreen Terrace\", \"town\" : \"Springfield\" } } }";

0 commit comments

Comments
 (0)