Fix bad iterator comparaison when resolving json pointer

When resolving a json pointer and use an empty string as a
referenceToken, the value is coerced as an empty object and a temporary empty
object is returned from 'asObject()'. Then we used to compare 2
iterators from 2 differents temporary empty objects.
This commit is contained in:
Cédric CARRÉE 2020-01-07 16:36:56 +01:00
parent 0abf633bc0
commit 4338affeb3
2 changed files with 32 additions and 2 deletions

View File

@ -215,9 +215,11 @@ inline AdapterType resolveJsonPointer(
} else if (node.maybeObject()) {
// Fragment must identify a member of the candidate object
typedef typename AdapterType::Object Object;
typename Object::const_iterator itr = node.asObject().find(
const Object object = node.asObject();
typename Object::const_iterator itr = object.find(
referenceToken);
if (itr == node.asObject().end()) {
if (itr == object.end()) {
throw std::runtime_error("Expected reference token to identify an "
"element in the current object; "
"actual token: " + referenceToken);

View File

@ -103,6 +103,34 @@ std::vector<std::shared_ptr<JsonPointerTestCase> >
testCase->expectedValue = NULL;
testCases.push_back(testCase);
{
rapidjson::Value nonemptyString;
nonemptyString.SetString("hello, world");
testCase = std::make_shared<JsonPointerTestCase>(
"Resolve '/value/foo' fails because 'value' is not an object (but a non empty string)");
testCase->value.SetObject();
testCase->value.AddMember("value", nonemptyString, allocator);
testCase->jsonPointer = "/value/bar";
testCase->expectedValue = &testCase->value;
testCase->expectedValue = NULL;
testCases.push_back(testCase);
}
{
rapidjson::Value emptyString;
emptyString.SetString("");
testCase = std::make_shared<JsonPointerTestCase>(
"Resolve '/empty/after_empty' fails because 'empty' is an empty string");
testCase->value.SetObject();
testCase->value.AddMember("empty", emptyString, allocator);
testCase->jsonPointer = "/empty/after_empty";
testCase->expectedValue = NULL;
testCases.push_back(testCase);
}
{
rapidjson::Value testArray;
testArray.SetArray();