mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
#3136: Fixed null character issue when parsing a JSON
This commit is contained in:
parent
e4b258765e
commit
e577e36c25
@ -204,7 +204,12 @@ void ParserImpl::handle()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JSON_STRING:
|
case JSON_STRING:
|
||||||
if (_pHandler) _pHandler->value(std::string(json_get_string(_pJSON, NULL)));
|
if (_pHandler)
|
||||||
|
{
|
||||||
|
std::size_t length = 0;
|
||||||
|
const char* val = json_get_string(_pJSON, &length);
|
||||||
|
_pHandler->value(std::string(val, length == 0 ? 0 : length - 1)); // Decrease the length by 1 because it also contains the terminating null character
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case JSON_OBJECT:
|
case JSON_OBJECT:
|
||||||
if (_pHandler) _pHandler->startObject();
|
if (_pHandler) _pHandler->startObject();
|
||||||
|
@ -1935,6 +1935,15 @@ void JSONTest::testEscape0()
|
|||||||
json->stringify(ss);
|
json->stringify(ss);
|
||||||
|
|
||||||
assertTrue (ss.str().compare("{\"name\":\"B\\u0000b\"}") == 0);
|
assertTrue (ss.str().compare("{\"name\":\"B\\u0000b\"}") == 0);
|
||||||
|
|
||||||
|
// parse the JSON containing the escaped string
|
||||||
|
Poco::JSON::Parser parser(new Poco::JSON::ParseHandler());
|
||||||
|
Var result = parser.parse(ss.str());
|
||||||
|
|
||||||
|
assert(result.type() == typeid(Object::Ptr));
|
||||||
|
|
||||||
|
Object::Ptr object = result.extract<Object::Ptr>();
|
||||||
|
assert(object->get("name").extract<std::string>() == nullString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user