Fix array indexing bug in JSON Pointer implementation

This commit is contained in:
Tristan Penman 2015-05-07 09:07:26 +10:00
parent c43c8568f5
commit b4c2dbd875
2 changed files with 17 additions and 1 deletions

View File

@ -78,7 +78,8 @@ inline AdapterType resolveJsonPointer(
} else if (node.isArray()) {
try {
// Fragment must be non-negative integer
const uint64_t index = boost::lexical_cast<uint64_t>(jsonPointer);
const uint64_t index = boost::lexical_cast<uint64_t>(
referenceToken);
typedef typename AdapterType::Array Array;
typename Array::const_iterator itr = node.asArray().begin();

View File

@ -104,6 +104,21 @@ std::vector<boost::shared_ptr<JsonPointerTestCase> >
testCase->expectedValue = NULL;
testCases.push_back(testCase);
rapidjson::Value testArray;
testArray.SetArray();
testArray.PushBack("test0", allocator);
testArray.PushBack("test1", allocator);
testArray.PushBack("test2", allocator);
testCase = boost::make_shared<JsonPointerTestCase>(
"Resolve '/test/1' in object containing one member containing "
"an array with 3 elements");
testCase->value.SetObject();
testCase->value.AddMember("test", testArray, allocator);
testCase->jsonPointer = "/test/1";
testCase->expectedValue = &testCase->value.FindMember("test")->value[1];
testCases.push_back(testCase);
return testCases;
}