mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-19 00:46:03 +01:00
Stringify escapes every unicode symbol when object contain an array #2364
This commit is contained in:
parent
312dc3325b
commit
f06580611f
@ -216,7 +216,7 @@ private:
|
||||
|
||||
inline void Array::setEscapeUnicode(bool escape)
|
||||
{
|
||||
_escapeUnicode = true;
|
||||
_escapeUnicode = escape;
|
||||
}
|
||||
|
||||
|
||||
|
@ -296,7 +296,7 @@ private:
|
||||
|
||||
inline void Object::setEscapeUnicode(bool escape)
|
||||
{
|
||||
_escapeUnicode = true;
|
||||
_escapeUnicode = escape;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user