Skip to content

Commit 0fd2875

Browse files
committed
fix get() for embedded zeroes in key
This method had been overlooked.
1 parent d31151d commit 0fd2875

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/json/value.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,19 @@ Json::Value obj_value(Json::objectValue); // {}
404404
const Value& operator[](const CppTL::ConstString& key) const;
405405
#endif
406406
/// Return the member named key if it exist, defaultValue otherwise.
407+
/// \note deep copy
407408
Value get(const char* key, const Value& defaultValue) const;
408409
/// Return the member named key if it exist, defaultValue otherwise.
410+
/// \note deep copy
409411
/// \param key may contain embedded nulls.
410412
Value get(const char* key, const char* end, const Value& defaultValue) const;
411413
/// Return the member named key if it exist, defaultValue otherwise.
414+
/// \note deep copy
412415
/// \param key may contain embedded nulls.
413416
Value get(const std::string& key, const Value& defaultValue) const;
414417
#ifdef JSON_USE_CPPTL
415418
/// Return the member named key if it exist, defaultValue otherwise.
419+
/// \note deep copy
416420
Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
417421
#endif
418422
/// Most general and efficient version of isMember()const, get()const,

src/lib_json/json_value.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,8 @@ Value& Value::append(const Value& value) { return (*this)[size()] = value; }
10281028

10291029
Value Value::get(char const* key, char const* end, Value const& defaultValue) const
10301030
{
1031-
const Value* value = &((*this)[key]);
1032-
return value == &nullRef ? defaultValue : *value;
1031+
Value const* found = find(key, end);
1032+
return !found ? defaultValue : *found;
10331033
}
10341034
Value Value::get(char const* key, Value const& defaultValue) const
10351035
{
@@ -1104,7 +1104,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
11041104
#ifdef JSON_USE_CPPTL
11051105
Value Value::get(const CppTL::ConstString& key,
11061106
const Value& defaultValue) const {
1107-
return get(key.c_str(), defaultValue);
1107+
return get(key.c_str(), key.end_c_str(), defaultValue);
11081108
}
11091109
#endif
11101110

0 commit comments

Comments
 (0)