mirror of
https://github.com/dropbox/json11.git
synced 2024-11-21 03:13:49 +08:00
* has_shape() return true for NUL type only if element actually exists
This commit is contained in:
parent
8ccf1f0c5e
commit
e2e3a11e99
@ -775,8 +775,10 @@ bool Json::has_shape(const shape & types, string & err) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& obj_items = object_items();
|
||||
for (auto & item : types) {
|
||||
if ((*this)[item.first].type() != item.second) {
|
||||
const auto it = obj_items.find(item.first);
|
||||
if (it == obj_items.cend() || it->second.type() != item.second) {
|
||||
err = "bad type for " + item.first + " in " + dump();
|
||||
return false;
|
||||
}
|
||||
|
5
test.cpp
5
test.cpp
@ -245,6 +245,11 @@ JSON11_TEST_CASE(json11_test) {
|
||||
std::string points_json = Json(points).dump();
|
||||
std::cout << "points_json: " << points_json << "\n";
|
||||
JSON11_TEST_ASSERT(points_json == "[[1, 2], [10, 20], [100, 200]]");
|
||||
|
||||
JSON11_TEST_ASSERT(((Json)(Json::object { { "foo", nullptr } })).has_shape({ { "foo", Json::NUL } }, err) == true);
|
||||
JSON11_TEST_ASSERT(((Json)(Json::object { { "foo", 1234567 } })).has_shape({ { "foo", Json::NUL } }, err) == false);
|
||||
JSON11_TEST_ASSERT(((Json)(Json::object { { "bar", 1234567 } })).has_shape({ { "foo", Json::NUL } }, err) == false);
|
||||
|
||||
}
|
||||
|
||||
#if JSON11_TEST_STANDALONE_MAIN
|
||||
|
Loading…
Reference in New Issue
Block a user