GH #118: JSON::Object::stringify endless loop

This commit is contained in:
aleks-f 2013-03-06 21:21:40 -06:00
parent dc5c8c87da
commit 727e3cd28d
7 changed files with 50 additions and 53 deletions

View File

@ -13,10 +13,12 @@ Release 1.5.2 (2013-03-??)
- merged GH #86: Invalid pointers to vector internals (by Adrian Imboden) - merged GH #86: Invalid pointers to vector internals (by Adrian Imboden)
- automatic library initialization macros - automatic library initialization macros
- fixed GH #110: WebSocket accept() fails when Connection header contains multiple tokens - fixed GH #110: WebSocket accept() fails when Connection header contains multiple tokens
- fixed GH# 71: WebSocket and broken Timeouts (POCO_BROKEN_TIMEOUTS) - fixed GH #71: WebSocket and broken Timeouts (POCO_BROKEN_TIMEOUTS)
- fixed a warning in Poco/Crypto/OpenSSLInitializer.h - fixed a warning in Poco/Crypto/OpenSSLInitializer.h
- fixed GH# 109: Bug in Poco::Net::SMTPClientSession::loginUsingPlain - fixed GH #109: Bug in Poco::Net::SMTPClientSession::loginUsingPlain
- added clang libc++ build configurations for Darwin and iPhone (Andrea Bigagli) - added clang libc++ build configurations for Darwin and iPhone (Andrea Bigagli)
- fixed GH #116: Wrong timezone parsing in DateTimeParse (fix by Matej Knopp)
- fixed GH #118: JSON::Object::stringify endless loop
Release 1.5.1 (2013-01-11) Release 1.5.1 (2013-01-11)
========================== ==========================

View File

@ -32,6 +32,7 @@ Roger Meier
Mathaus Mendel Mathaus Mendel
Arturo Castro Arturo Castro
Adrian Imboden Adrian Imboden
Matej Knopp
-- --
$Id$ $Id$

View File

@ -146,6 +146,7 @@ public:
/// Removes the property with the given key /// Removes the property with the given key
private: private:
//TODO: unordered map
typedef std::map<std::string, Dynamic::Var> ValueMap; typedef std::map<std::string, Dynamic::Var> ValueMap;
ValueMap _values; ValueMap _values;
}; };

View File

@ -123,41 +123,22 @@ bool Array::isObject(unsigned int index) const
void Array::stringify(std::ostream& out, unsigned int indent) const void Array::stringify(std::ostream& out, unsigned int indent) const
{ {
out << "["; out << "[";
if ( indent > 0 )
out << std::endl;
for(ValueVec::const_iterator it = _values.begin(); it != _values.end();) if (indent > 0) out << std::endl;
for (ValueVec::const_iterator it = _values.begin(); it != _values.end();)
{ {
for(int i = 0; i < indent; i++) for(int i = 0; i < indent; i++) out << ' ';
{
out << ' ';
}
Stringifier::stringify(*it, out, indent); Stringifier::stringify(*it, out, indent);
if ( ++it != _values.end() ) if ( ++it != _values.end() )
{ {
out << ","; out << ",";
if ( indent > 0 ) if ( indent > 0 ) out << std::endl;
{
out << std::endl;
}
} }
} }
if ( indent > 0 )
{
out << std::endl;
}
if ( indent > 0 )
indent -= 2;
for(int i = 0; i < indent; i++)
{
out << ' ';
}
out << "]"; out << "]";
} }

View File

@ -117,41 +117,23 @@ void Object::getNames(std::vector<std::string>& names) const
void Object::stringify(std::ostream& out, unsigned int indent) const void Object::stringify(std::ostream& out, unsigned int indent) const
{ {
out << '{'; out << '{';
if ( indent > 0 )
{
out << std::endl;
}
for(ValueMap::const_iterator it = _values.begin(); it != _values.end();) if (indent > 0) out << std::endl;
for (ValueMap::const_iterator it = _values.begin(); it != _values.end();)
{ {
for(int i = 0; i < indent; i++) for(int i = 0; i < indent; i++) out << ' ';
{
out << ' ';
}
out << '"' << it->first << '"'; out << '"' << it->first << '"';
out << (( indent > 0 ) ? " : " : ":"); out << (( indent > 0 ) ? " : " : ":");
Stringifier::stringify(it->second, out, indent); Stringifier::stringify(it->second, out, indent);
if ( ++it != _values.end() ) if ( ++it != _values.end() ) out << ',';
{
out << ',';
}
if ( indent > 0 ) if ( indent > 0 ) out << std::endl;
{
out << std::endl;
}
} }
if ( indent > 0 )
indent -= 2;
for(int i = 0; i < indent; i++)
{
out << ' ';
}
out << '}'; out << '}';
} }

View File

@ -195,7 +195,7 @@ void JSONTest::testNumberProperty()
void JSONTest::testUnsignedNumberProperty() void JSONTest::testUnsignedNumberProperty()
{ {
// 4294967295 == unsigned(-1) // 4294967295 == unsigned(-1)
std::string json = "{ \"test\" : 4294967295 }"; std::string json = "{ \"test\" : 4294967295 }";
Parser parser; Parser parser;
Var result; Var result;
@ -256,7 +256,7 @@ void JSONTest::testNumber64Property()
void JSONTest::testUnsignedNumber64Property() void JSONTest::testUnsignedNumber64Property()
{ {
// 18446744073709551615 == UInt64(-1) // 18446744073709551615 == UInt64(-1)
std::string json = "{ \"test\" : 18446744073709551615 }"; std::string json = "{ \"test\" : 18446744073709551615 }";
Parser parser; Parser parser;
Var result; Var result;
@ -801,6 +801,33 @@ void JSONTest::testQuery()
} }
void JSONTest::testStringify()
{
std::string json = "{ \"name\" : \"Franky\", \"children\" : [ \"Jonas\", \"Ellen\" ] }";
Parser parser;
Var result;
try
{
DefaultHandler handler;
parser.setHandler(&handler);
parser.parse(json);
result = handler.result();
}
catch(JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assert(false);
}
assert(result.type() == typeid(Object::Ptr));
std::ostringstream ostr;
Stringifier::stringify(result, ostr);
//TODO: need map that does not order for internal container
assert (ostr.str() == "{\"name\":\"Franky\",\"children\":[\"Jonas\",\"Ellen\"]}");
}
void JSONTest::testValidJanssonFiles() void JSONTest::testValidJanssonFiles()
{ {
Poco::Path pathPattern(getTestFilesPath("valid")); Poco::Path pathPattern(getTestFilesPath("valid"));
@ -1044,6 +1071,7 @@ CppUnit::Test* JSONTest::suite()
CppUnit_addTest(pSuite, JSONTest, testDoubleElement); CppUnit_addTest(pSuite, JSONTest, testDoubleElement);
CppUnit_addTest(pSuite, JSONTest, testOptValue); CppUnit_addTest(pSuite, JSONTest, testOptValue);
CppUnit_addTest(pSuite, JSONTest, testQuery); CppUnit_addTest(pSuite, JSONTest, testQuery);
CppUnit_addTest(pSuite, JSONTest, testStringify);
CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles); CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles);
CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles); CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles);
CppUnit_addTest(pSuite, JSONTest, testInvalidUnicodeJanssonFiles); CppUnit_addTest(pSuite, JSONTest, testInvalidUnicodeJanssonFiles);

View File

@ -73,6 +73,8 @@ public:
void testDoubleElement(); void testDoubleElement();
void testOptValue(); void testOptValue();
void testQuery(); void testQuery();
void testStringify();
void testValidJanssonFiles(); void testValidJanssonFiles();
void testInvalidJanssonFiles(); void testInvalidJanssonFiles();
void testTemplate(); void testTemplate();