From d31151d150dd510da9edb18fcabff5b3867de912 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 5 Mar 2015 16:44:41 -0600 Subject: [PATCH] test get(key, default) --- src/lib_json/json_value.cpp | 2 +- src/test_lib_json/main.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 1ade74a..cefd05e 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1037,7 +1037,7 @@ Value Value::get(char const* key, Value const& defaultValue) const } Value Value::get(std::string const& key, Value const& defaultValue) const { - return get(key.c_str(), defaultValue); + return get(key.data(), key.data() + key.length(), defaultValue); } diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 25a334b..a52cc78 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1578,6 +1578,7 @@ JSONTEST_FIXTURE(ValueTest, zeroesInKeys) { JSONTEST_ASSERT_STRING_EQUAL("there", root[binary].asString()); JSONTEST_ASSERT(!root.isMember("hi")); JSONTEST_ASSERT(root.isMember(binary)); + JSONTEST_ASSERT_STRING_EQUAL("there", root.get(binary, Json::Value::nullRef).asString()); Json::Value removed; bool did; did = root.removeMember(binary.data(), binary.data() + binary.length(), @@ -1588,6 +1589,8 @@ JSONTEST_FIXTURE(ValueTest, zeroesInKeys) { &removed); JSONTEST_ASSERT(!did); JSONTEST_ASSERT_STRING_EQUAL("there", removed.asString()); // still + JSONTEST_ASSERT(!root.isMember(binary)); + JSONTEST_ASSERT_STRING_EQUAL("", root.get(binary, Json::Value::nullRef).asString()); } }