mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-21 06:37:42 +01:00
fix(JSON::Stringifier): JSON Serializing NAN #3251
This commit is contained in:
parent
5cbe30e199
commit
cafd56a947
@ -62,6 +62,8 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
|
||||
else if (any.isNumeric() || any.isBoolean())
|
||||
{
|
||||
std::string value = any.convert<std::string>();
|
||||
if ((Poco::icompare(value, "nan") == 0) ||
|
||||
(Poco::icompare(value, "inf") == 0)) value = "null";
|
||||
if (any.type() == typeid(char)) formatString(value, out, options);
|
||||
else out << value;
|
||||
}
|
||||
|
@ -1586,6 +1586,17 @@ void JSONTest::testStringify()
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testStringifyNaN()
|
||||
{
|
||||
Object::Ptr o = new Object;
|
||||
o->set("NaN", NAN);
|
||||
o->set("Infinity", INFINITY);
|
||||
std::ostringstream stream;
|
||||
o->stringify(stream, 0);
|
||||
assertEqual (stream.str(), std::string(R"({"Infinity":null,"NaN":null})"));
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testStringifyPreserveOrder()
|
||||
{
|
||||
Object presObj(Poco::JSON_PRESERVE_KEY_ORDER);
|
||||
@ -2361,6 +2372,7 @@ CppUnit::Test* JSONTest::suite()
|
||||
CppUnit_addTest(pSuite, JSONTest, testComment);
|
||||
CppUnit_addTest(pSuite, JSONTest, testPrintHandler);
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringify);
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringifyNaN);
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringifyPreserveOrder);
|
||||
CppUnit_addTest(pSuite, JSONTest, testVarConvert);
|
||||
CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles);
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
void testComment();
|
||||
void testPrintHandler();
|
||||
void testStringify();
|
||||
void testStringifyNaN();
|
||||
void testStringifyPreserveOrder();
|
||||
void testVarConvert();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user