Stringify escapes every unicode symbol when object contain an array #2364

This commit is contained in:
Alex Fabijanic 2018-06-12 10:17:08 -05:00
parent 312dc3325b
commit f06580611f
3 changed files with 10 additions and 7 deletions

View File

@ -216,7 +216,7 @@ private:
inline void Array::setEscapeUnicode(bool escape)
{
_escapeUnicode = true;
_escapeUnicode = escape;
}

View File

@ -296,7 +296,7 @@ private:
inline void Object::setEscapeUnicode(bool escape)
{
_escapeUnicode = true;
_escapeUnicode = escape;
}

View File

@ -1938,26 +1938,29 @@ void JSONTest::testEscape0()
void JSONTest::testNonEscapeUnicode()
{
std::string chinese("{ \"name\" : \"\\u4e2d\" }");
std::string chinese("{\"arr\":[{ \"name\" : \"\\u4e2d\" }]}");
Poco::JSON::Parser parser(new Poco::JSON::ParseHandler());
Var result = parser.parse(chinese);
assertTrue (result.type() == typeid(Object::Ptr));
Object::Ptr object = result.extract<Object::Ptr>();
object->setEscapeUnicode(false);
std::stringstream ss;
object->stringify(ss);
assertTrue (ss.str().compare("{\"name\":\"\xE4\xB8\xAD\"}") == 0);
assertTrue (ss.str().compare("{\"arr\":[{\"name\":\"\xE4\xB8\xAD\"}]}") == 0);
const unsigned char utf8Chars[] = {'{', '"', 'n', 'a', 'm', 'e', '"', ':',
'"', 'g', 0xC3, 0xBC, 'n', 't', 'e', 'r', '"', '}', 0};
const unsigned char utf8Chars[] = {'{', '"', 'a', 'r', 'r', '"', ':', '[', '{', '"', 'n', 'a', 'm', 'e', '"', ':',
'"', 'g', 0xC3, 0xBC, 'n', 't', 'e', 'r', '"', '}', ']', '}', 0};
std::string utf8Text((const char*) utf8Chars);
parser.reset();
result = parser.parse(utf8Text);
object = result.extract<Object::Ptr>();
object->setEscapeUnicode(false);
ss.str(""); object->stringify(ss);
assertTrue (ss.str() == "{\"name\":\"g\xC3\xBCnter\"}");
assertTrue (ss.str() == "{\"arr\":[{\"name\":\"g\xC3\xBCnter\"}]}");
Poco::JSON::Object obj1;
std::string shortEscapeStr("String with \t");