Skip to content

Commit

Permalink
🚨 fixed a linter warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Oct 31, 2018
1 parent e3c28af commit 2f73a4d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ class binary_reader

if (not is_array)
{
sax->key(key);
if (not sax->key(key))
{
return false;
}
}

if (JSON_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
Expand Down
5 changes: 4 additions & 1 deletion single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6635,7 +6635,10 @@ class binary_reader

if (not is_array)
{
sax->key(key);
if (not sax->key(key))
{
return false;
}
}

if (JSON_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
Expand Down
22 changes: 22 additions & 0 deletions test/src/unit-bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,28 @@ TEST_CASE("Incomplete BSON Input")
SaxCountdown scp(0);
CHECK(not json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
}

SECTION("Improve coverage")
{
SECTION("key")
{
json j = {{"key", "value"}};
auto bson_vec = json::to_bson(j);
SaxCountdown scp(2);
CHECK(not json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
}

SECTION("array")
{
json j =
{
{ "entry", json::array() }
};
auto bson_vec = json::to_bson(j);
SaxCountdown scp(2);
CHECK(not json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
}
}
}

TEST_CASE("Unsupported BSON input")
Expand Down

0 comments on commit 2f73a4d

Please sign in to comment.