diff --git a/include/valijson/internal/json_pointer.hpp b/include/valijson/internal/json_pointer.hpp index ca978bc..e22fada 100644 --- a/include/valijson/internal/json_pointer.hpp +++ b/include/valijson/internal/json_pointer.hpp @@ -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); diff --git a/tests/test_json_pointer.cpp b/tests/test_json_pointer.cpp index 47a7d63..2e7dfe1 100644 --- a/tests/test_json_pointer.cpp +++ b/tests/test_json_pointer.cpp @@ -103,6 +103,34 @@ std::vector > testCase->expectedValue = NULL; testCases.push_back(testCase); + { + rapidjson::Value nonemptyString; + nonemptyString.SetString("hello, world"); + + + testCase = std::make_shared( + "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( + "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();