Skip to content

Commit

Permalink
Merge branch 'develop' into issue550
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryRLee committed Jun 5, 2017
2 parents f2e1643 + 1a9d766 commit 2ba554e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6381,7 +6381,7 @@ class basic_json
{
case value_t::array:
{
return *lhs.m_value.array < *rhs.m_value.array;
return (*lhs.m_value.array) < (*rhs.m_value.array);
}
case value_t::object:
{
Expand Down Expand Up @@ -8799,7 +8799,7 @@ class basic_json
// store number of bytes in the buffer
fill_size = static_cast<size_t>(is.gcount());

// skip byte-order mark
// skip byte order mark
if (fill_size >= 3 and buffer[0] == '\xEF' and buffer[1] == '\xBB' and buffer[2] == '\xBF')
{
buffer_pos += 3;
Expand Down Expand Up @@ -8896,7 +8896,13 @@ class basic_json
public:
input_buffer_adapter(const char* b, size_t l)
: input_adapter(), cursor(b), limit(b + l), start(b)
{}
{
// skip byte order mark
if (l >= 3 and b[0] == '\xEF' and b[1] == '\xBB' and b[2] == '\xBF')
{
cursor += 3;
}
}

// delete because of pointer members
input_buffer_adapter(const input_buffer_adapter&) = delete;
Expand Down
8 changes: 8 additions & 0 deletions test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ TEST_CASE("regression tests")
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
}

/*
SECTION("second example from #529")
{
std::string str = "{\n\"one\" : 1,\n\"two\" : 2\n}\n{\n\"three\" : 3\n}";
Expand Down Expand Up @@ -748,6 +749,7 @@ TEST_CASE("regression tests")
std::remove("test.json");
}
*/
}

SECTION("issue #389 - Integer-overflow (OSS-Fuzz issue 267)")
Expand Down Expand Up @@ -1167,4 +1169,10 @@ TEST_CASE("regression tests")
std::vector<uint8_t> vec = {'"', '\\', '"', 'X', '"', '"'};
CHECK_THROWS_AS(json::parse(vec), json::parse_error);
}

SECTION("issue #602 - BOM not skipped when using json:parse(iterator)")
{
std::string i = "\xef\xbb\xbf{\n \"foo\": true\n}";
CHECK_NOTHROW(json::parse(i.begin(), i.end()));
}
}
17 changes: 13 additions & 4 deletions test/src/unit-unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,19 @@ TEST_CASE("Unicode", "[hide]")

SECTION("ignore byte-order-mark")
{
// read a file with a UTF-8 BOM
std::ifstream f("test/data/json_nlohmann_tests/bom.json");
json j;
CHECK_NOTHROW(f >> j);
SECTION("in a stream")
{
// read a file with a UTF-8 BOM
std::ifstream f("test/data/json_nlohmann_tests/bom.json");
json j;
CHECK_NOTHROW(f >> j);
}

SECTION("with an iterator")
{
std::string i = "\xef\xbb\xbf{\n \"foo\": true\n}";
CHECK_NOTHROW(json::parse(i.begin(), i.end()));
}
}

SECTION("error for incomplete/wrong BOM")
Expand Down

0 comments on commit 2ba554e

Please sign in to comment.