Only escape string values in Poco::JSON::Stringifier::stringify() #1027

This commit is contained in:
Alex Fabijanic
2016-04-23 14:52:03 -06:00
parent b14b6f3d7f
commit 0286d245ab
3 changed files with 56 additions and 22 deletions

View File

@@ -23,6 +23,8 @@
#include "Poco/TextConverter.h"
#include "Poco/Nullable.h"
#include "Poco/Dynamic/Struct.h"
#include "Poco/DateTime.h"
#include "Poco/DateTimeFormatter.h"
#include <set>
#include <iostream>
@@ -30,7 +32,8 @@
using namespace Poco::JSON;
using namespace Poco::Dynamic;
using Poco::DynamicStruct;
using Poco::DateTime;
using Poco::DateTimeFormatter;
JSONTest::JSONTest(const std::string& name): CppUnit::TestCase("JSON")
{
@@ -897,6 +900,12 @@ void JSONTest::testStringElement()
Poco::Dynamic::Array da = *array;
assert (da.size() == 1);
assert (da[0] == "value");
std::stringstream s;
json = "[ \"\\u0017\" ]";
Var v = Parser().parse(json);
Stringifier::condense(v, s);
assert(s.str() == "[\"\\u0017\"]");
}
@@ -1245,6 +1254,27 @@ void JSONTest::testPrintHandler()
void JSONTest::testStringify()
{
std::ostringstream os;
Var i = 123;
Stringifier::stringify(i, os);
assert(os.str() == "123");
os.str("");
Var f = 123.456;
Stringifier::stringify(f, os);
assert(os.str() == "123.456");
os.str("");
Var s = "abcdef";
Stringifier::stringify(s, os);
assert(os.str() == "\"abcdef\"");
os.str("");
DateTime dt;
Var d = dt;
Stringifier::stringify(d, os);
assert(os.str() == std::string("\"" + DateTimeFormatter::format(dt, Poco::DateTimeFormat::ISO8601_FORMAT) + "\""));
std::string str1 = "\r";
std::string str2 = "\n";
Poco::JSON::Object obj1, obj2;