From b4c2dbd87547faf3ec675c0cfcc073c7592f7f0a Mon Sep 17 00:00:00 2001 From: Tristan Penman Date: Thu, 7 May 2015 09:07:26 +1000 Subject: [PATCH] Fix array indexing bug in JSON Pointer implementation --- include/valijson/internal/json_pointer.hpp | 3 ++- tests/test_json_pointer.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/valijson/internal/json_pointer.hpp b/include/valijson/internal/json_pointer.hpp index 093cf47..b7afd2c 100644 --- a/include/valijson/internal/json_pointer.hpp +++ b/include/valijson/internal/json_pointer.hpp @@ -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(jsonPointer); + const uint64_t index = boost::lexical_cast( + referenceToken); typedef typename AdapterType::Array Array; typename Array::const_iterator itr = node.asArray().begin(); diff --git a/tests/test_json_pointer.cpp b/tests/test_json_pointer.cpp index 3d4343b..b435f4f 100644 --- a/tests/test_json_pointer.cpp +++ b/tests/test_json_pointer.cpp @@ -104,6 +104,21 @@ std::vector > 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( + "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; }