mirror of
https://github.com/nlohmann/json.git
synced 2026-09-07 16:57:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f5dbb56c5 |
@@ -34,10 +34,14 @@ void swap(typename binary_t::container_type& other);
|
|||||||
```
|
```
|
||||||
|
|
||||||
1. Exchanges the contents of the JSON value with those of `other`. Does not invoke any move, copy, or swap operations on
|
1. Exchanges the contents of the JSON value with those of `other`. Does not invoke any move, copy, or swap operations on
|
||||||
individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
|
individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated. If macro
|
||||||
|
[`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) is defined to `#!cpp 1`, the
|
||||||
|
[`start_pos()`](start_pos.md)/[`end_pos()`](end_pos.md) diagnostic positions are exchanged along with the value.
|
||||||
2. Exchanges the contents of the JSON value from `left` with those of `right`. Does not invoke any move, copy, or swap
|
2. Exchanges the contents of the JSON value from `left` with those of `right`. Does not invoke any move, copy, or swap
|
||||||
operations on individual elements. All iterators and references remain valid. The past-the-end iterator is
|
operations on individual elements. All iterators and references remain valid. The past-the-end iterator is
|
||||||
invalidated. Implemented as a friend function callable via ADL.
|
invalidated. Implemented as a friend function callable via ADL. If macro
|
||||||
|
[`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) is defined to `#!cpp 1`, the
|
||||||
|
[`start_pos()`](start_pos.md)/[`end_pos()`](end_pos.md) diagnostic positions are exchanged along with the value.
|
||||||
3. Exchanges the contents of a JSON array with those of `other`. Does not invoke any move, copy, or swap operations on
|
3. Exchanges the contents of a JSON array with those of `other`. Does not invoke any move, copy, or swap operations on
|
||||||
individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
|
individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
|
||||||
4. Exchanges the contents of a JSON object with those of `other`. Does not invoke any move, copy, or swap operations on
|
4. Exchanges the contents of a JSON object with those of `other`. Does not invoke any move, copy, or swap operations on
|
||||||
|
|||||||
@@ -996,21 +996,23 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief reads a definite-length CBOR string
|
@brief reads a CBOR string
|
||||||
|
|
||||||
Reads everything @ref get_cbor_string accepts except the indefinite-length
|
This function first reads starting bytes to determine the expected
|
||||||
form, which that function handles itself. The bytes are appended to @a
|
string length and then copies this number of bytes into a string.
|
||||||
result, so consecutive chunks of an indefinite-length string can be read
|
Additionally, CBOR's strings with indefinite lengths are supported.
|
||||||
into the same string.
|
|
||||||
|
|
||||||
@param[out] result string the bytes are appended to
|
@param[out] result created string
|
||||||
|
|
||||||
@return whether string creation completed
|
@return whether string creation completed
|
||||||
|
|
||||||
@pre @a current is not EOF
|
|
||||||
*/
|
*/
|
||||||
bool get_cbor_string_chunk(string_t& result)
|
bool get_cbor_string(string_t& result)
|
||||||
{
|
{
|
||||||
|
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (current)
|
switch (current)
|
||||||
{
|
{
|
||||||
// UTF-8 string (0x00..0x17 bytes follow)
|
// UTF-8 string (0x00..0x17 bytes follow)
|
||||||
@@ -1066,6 +1068,20 @@ class binary_reader
|
|||||||
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
|
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 0x7F: // UTF-8 string (indefinite length)
|
||||||
|
{
|
||||||
|
while (get() != 0xFF)
|
||||||
|
{
|
||||||
|
string_t chunk;
|
||||||
|
if (!get_cbor_string(chunk))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
result.append(chunk);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
@@ -1076,82 +1092,23 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief reads a CBOR string
|
@brief reads a CBOR byte array
|
||||||
|
|
||||||
This function first reads starting bytes to determine the expected
|
This function first reads starting bytes to determine the expected
|
||||||
string length and then copies this number of bytes into a string.
|
byte array length and then copies this number of bytes into the byte array.
|
||||||
Additionally, CBOR's strings with indefinite lengths are supported.
|
Additionally, CBOR's byte arrays with indefinite lengths are supported.
|
||||||
|
|
||||||
@param[out] result created string
|
@param[out] result created byte array
|
||||||
|
|
||||||
@return whether string creation completed
|
|
||||||
*/
|
|
||||||
bool get_cbor_string(string_t& result)
|
|
||||||
{
|
|
||||||
// number of indefinite-length strings that have been opened and not
|
|
||||||
// closed yet. RFC 8949, Section 3.2.3 does not permit nesting them,
|
|
||||||
// but this reader has always accepted it, so the open levels are
|
|
||||||
// counted instead of recursed through, which overflowed the stack for
|
|
||||||
// an input of repeated 0x7F bytes (see #5104). Every chunk is appended
|
|
||||||
// to the same result, so no per-level state is needed.
|
|
||||||
std::size_t open = 0;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current == 0x7F) // UTF-8 string (indefinite length)
|
|
||||||
{
|
|
||||||
++open;
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// a break marker closes the innermost indefinite-length string;
|
|
||||||
// outside of one it is not a string and falls through to the error
|
|
||||||
if (open != 0 && current == 0xFF)
|
|
||||||
{
|
|
||||||
if (--open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string_chunk(result)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief reads a definite-length CBOR byte array
|
|
||||||
|
|
||||||
Reads everything @ref get_cbor_binary accepts except the indefinite-length
|
|
||||||
form, which that function handles itself. The bytes are appended to @a
|
|
||||||
result, so consecutive chunks of an indefinite-length byte array can be
|
|
||||||
read into the same byte array.
|
|
||||||
|
|
||||||
@param[out] result byte array the bytes are appended to
|
|
||||||
|
|
||||||
@return whether byte array creation completed
|
@return whether byte array creation completed
|
||||||
|
|
||||||
@pre @a current is not EOF
|
|
||||||
*/
|
*/
|
||||||
bool get_cbor_binary_chunk(binary_t& result)
|
bool get_cbor_binary(binary_t& result)
|
||||||
{
|
{
|
||||||
|
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (current)
|
switch (current)
|
||||||
{
|
{
|
||||||
// Binary data (0x00..0x17 bytes follow)
|
// Binary data (0x00..0x17 bytes follow)
|
||||||
@@ -1211,6 +1168,20 @@ class binary_reader
|
|||||||
get_binary(input_format_t::cbor, len, result);
|
get_binary(input_format_t::cbor, len, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 0x5F: // Binary data (indefinite length)
|
||||||
|
{
|
||||||
|
while (get() != 0xFF)
|
||||||
|
{
|
||||||
|
binary_t chunk;
|
||||||
|
if (!get_cbor_binary(chunk))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
result.insert(result.end(), chunk.begin(), chunk.end());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
@@ -1220,63 +1191,6 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief reads a CBOR byte array
|
|
||||||
|
|
||||||
This function first reads starting bytes to determine the expected
|
|
||||||
byte array length and then copies this number of bytes into the byte array.
|
|
||||||
Additionally, CBOR's byte arrays with indefinite lengths are supported.
|
|
||||||
|
|
||||||
@param[out] result created byte array
|
|
||||||
|
|
||||||
@return whether byte array creation completed
|
|
||||||
*/
|
|
||||||
bool get_cbor_binary(binary_t& result)
|
|
||||||
{
|
|
||||||
// the open indefinite-length byte arrays are counted rather than
|
|
||||||
// recursed through, for the reason given in @ref get_cbor_string
|
|
||||||
std::size_t open = 0;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current == 0x5F) // Binary data (indefinite length)
|
|
||||||
{
|
|
||||||
++open;
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// a break marker closes the innermost indefinite-length byte
|
|
||||||
// array; outside of one it falls through to the error below
|
|
||||||
if (open != 0 && current == 0xFF)
|
|
||||||
{
|
|
||||||
if (--open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!get_cbor_binary_chunk(result)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief narrow a definite CBOR array/map length to std::size_t
|
@brief narrow a definite CBOR array/map length to std::size_t
|
||||||
|
|
||||||
@@ -2477,12 +2391,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
result.first = npos; // size
|
result.first = npos; // size
|
||||||
result.second = 0; // type
|
result.second = 0; // type
|
||||||
// seed the flag with the caller's context: inside an ndarray dimension
|
bool is_ndarray = false;
|
||||||
// vector another ndarray is not allowed, and get_ubjson_size_value()
|
|
||||||
// rejects it up front instead of reading it and reporting afterwards.
|
|
||||||
// Seeding it with `false` made every '#' of a "[#[#[..." chain descend
|
|
||||||
// another level, which overflowed the stack (see #5104).
|
|
||||||
bool is_ndarray = inside_ndarray;
|
|
||||||
|
|
||||||
get_ignore_noop();
|
get_ignore_noop();
|
||||||
|
|
||||||
@@ -2515,11 +2424,13 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||||
// an ndarray was read here only if the flag flipped; when it was
|
if (input_format == input_format_t::bjdata && is_ndarray)
|
||||||
// seeded true, get_ubjson_size_value() already rejected the nested
|
|
||||||
// dimension vector
|
|
||||||
if (input_format == input_format_t::bjdata && is_ndarray && !inside_ndarray)
|
|
||||||
{
|
{
|
||||||
|
if (inside_ndarray)
|
||||||
|
{
|
||||||
|
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
||||||
|
exception_message(input_format, "ndarray can not be recursive", "size"), nullptr));
|
||||||
|
}
|
||||||
result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters
|
result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters
|
||||||
}
|
}
|
||||||
return is_error;
|
return is_error;
|
||||||
@@ -2528,7 +2439,7 @@ class binary_reader
|
|||||||
if (current == '#')
|
if (current == '#')
|
||||||
{
|
{
|
||||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||||
if (input_format == input_format_t::bjdata && is_ndarray && !inside_ndarray)
|
if (input_format == input_format_t::bjdata && is_ndarray)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
||||||
exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
||||||
|
|||||||
+33
-70
@@ -3547,6 +3547,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
std::swap(m_data.m_type, other.m_data.m_type);
|
std::swap(m_data.m_type, other.m_data.m_type);
|
||||||
std::swap(m_data.m_value, other.m_data.m_value);
|
std::swap(m_data.m_value, other.m_data.m_value);
|
||||||
|
|
||||||
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
|
std::swap(start_position, other.start_position);
|
||||||
|
std::swap(end_position, other.end_position);
|
||||||
|
#endif
|
||||||
|
|
||||||
set_parents();
|
set_parents();
|
||||||
other.set_parents();
|
other.set_parents();
|
||||||
assert_invariant();
|
assert_invariant();
|
||||||
@@ -4473,11 +4478,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in CBOR format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in CBOR format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -4493,11 +4495,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -4522,11 +4521,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in MessagePack format
|
/// @brief create a JSON value from an input in MessagePack format
|
||||||
@@ -4540,11 +4536,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in MessagePack format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in MessagePack format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -4559,11 +4552,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -4586,11 +4576,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in UBJSON format
|
/// @brief create a JSON value from an input in UBJSON format
|
||||||
@@ -4604,11 +4591,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in UBJSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in UBJSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -4623,11 +4607,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -4650,11 +4631,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BJData format
|
/// @brief create a JSON value from an input in BJData format
|
||||||
@@ -4668,11 +4646,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BJData format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in BJData format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -4687,11 +4662,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BSON format
|
/// @brief create a JSON value from an input in BSON format
|
||||||
@@ -4705,11 +4677,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in BSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -4724,11 +4693,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -4751,11 +4717,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|||||||
@@ -11683,21 +11683,23 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief reads a definite-length CBOR string
|
@brief reads a CBOR string
|
||||||
|
|
||||||
Reads everything @ref get_cbor_string accepts except the indefinite-length
|
This function first reads starting bytes to determine the expected
|
||||||
form, which that function handles itself. The bytes are appended to @a
|
string length and then copies this number of bytes into a string.
|
||||||
result, so consecutive chunks of an indefinite-length string can be read
|
Additionally, CBOR's strings with indefinite lengths are supported.
|
||||||
into the same string.
|
|
||||||
|
|
||||||
@param[out] result string the bytes are appended to
|
@param[out] result created string
|
||||||
|
|
||||||
@return whether string creation completed
|
@return whether string creation completed
|
||||||
|
|
||||||
@pre @a current is not EOF
|
|
||||||
*/
|
*/
|
||||||
bool get_cbor_string_chunk(string_t& result)
|
bool get_cbor_string(string_t& result)
|
||||||
{
|
{
|
||||||
|
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (current)
|
switch (current)
|
||||||
{
|
{
|
||||||
// UTF-8 string (0x00..0x17 bytes follow)
|
// UTF-8 string (0x00..0x17 bytes follow)
|
||||||
@@ -11753,6 +11755,20 @@ class binary_reader
|
|||||||
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
|
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 0x7F: // UTF-8 string (indefinite length)
|
||||||
|
{
|
||||||
|
while (get() != 0xFF)
|
||||||
|
{
|
||||||
|
string_t chunk;
|
||||||
|
if (!get_cbor_string(chunk))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
result.append(chunk);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
@@ -11763,82 +11779,23 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief reads a CBOR string
|
@brief reads a CBOR byte array
|
||||||
|
|
||||||
This function first reads starting bytes to determine the expected
|
This function first reads starting bytes to determine the expected
|
||||||
string length and then copies this number of bytes into a string.
|
byte array length and then copies this number of bytes into the byte array.
|
||||||
Additionally, CBOR's strings with indefinite lengths are supported.
|
Additionally, CBOR's byte arrays with indefinite lengths are supported.
|
||||||
|
|
||||||
@param[out] result created string
|
@param[out] result created byte array
|
||||||
|
|
||||||
@return whether string creation completed
|
|
||||||
*/
|
|
||||||
bool get_cbor_string(string_t& result)
|
|
||||||
{
|
|
||||||
// number of indefinite-length strings that have been opened and not
|
|
||||||
// closed yet. RFC 8949, Section 3.2.3 does not permit nesting them,
|
|
||||||
// but this reader has always accepted it, so the open levels are
|
|
||||||
// counted instead of recursed through, which overflowed the stack for
|
|
||||||
// an input of repeated 0x7F bytes (see #5104). Every chunk is appended
|
|
||||||
// to the same result, so no per-level state is needed.
|
|
||||||
std::size_t open = 0;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current == 0x7F) // UTF-8 string (indefinite length)
|
|
||||||
{
|
|
||||||
++open;
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// a break marker closes the innermost indefinite-length string;
|
|
||||||
// outside of one it is not a string and falls through to the error
|
|
||||||
if (open != 0 && current == 0xFF)
|
|
||||||
{
|
|
||||||
if (--open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string_chunk(result)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief reads a definite-length CBOR byte array
|
|
||||||
|
|
||||||
Reads everything @ref get_cbor_binary accepts except the indefinite-length
|
|
||||||
form, which that function handles itself. The bytes are appended to @a
|
|
||||||
result, so consecutive chunks of an indefinite-length byte array can be
|
|
||||||
read into the same byte array.
|
|
||||||
|
|
||||||
@param[out] result byte array the bytes are appended to
|
|
||||||
|
|
||||||
@return whether byte array creation completed
|
@return whether byte array creation completed
|
||||||
|
|
||||||
@pre @a current is not EOF
|
|
||||||
*/
|
*/
|
||||||
bool get_cbor_binary_chunk(binary_t& result)
|
bool get_cbor_binary(binary_t& result)
|
||||||
{
|
{
|
||||||
|
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (current)
|
switch (current)
|
||||||
{
|
{
|
||||||
// Binary data (0x00..0x17 bytes follow)
|
// Binary data (0x00..0x17 bytes follow)
|
||||||
@@ -11898,6 +11855,20 @@ class binary_reader
|
|||||||
get_binary(input_format_t::cbor, len, result);
|
get_binary(input_format_t::cbor, len, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 0x5F: // Binary data (indefinite length)
|
||||||
|
{
|
||||||
|
while (get() != 0xFF)
|
||||||
|
{
|
||||||
|
binary_t chunk;
|
||||||
|
if (!get_cbor_binary(chunk))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
result.insert(result.end(), chunk.begin(), chunk.end());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
auto last_token = get_token_string();
|
auto last_token = get_token_string();
|
||||||
@@ -11907,63 +11878,6 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief reads a CBOR byte array
|
|
||||||
|
|
||||||
This function first reads starting bytes to determine the expected
|
|
||||||
byte array length and then copies this number of bytes into the byte array.
|
|
||||||
Additionally, CBOR's byte arrays with indefinite lengths are supported.
|
|
||||||
|
|
||||||
@param[out] result created byte array
|
|
||||||
|
|
||||||
@return whether byte array creation completed
|
|
||||||
*/
|
|
||||||
bool get_cbor_binary(binary_t& result)
|
|
||||||
{
|
|
||||||
// the open indefinite-length byte arrays are counted rather than
|
|
||||||
// recursed through, for the reason given in @ref get_cbor_string
|
|
||||||
std::size_t open = 0;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current == 0x5F) // Binary data (indefinite length)
|
|
||||||
{
|
|
||||||
++open;
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// a break marker closes the innermost indefinite-length byte
|
|
||||||
// array; outside of one it falls through to the error below
|
|
||||||
if (open != 0 && current == 0xFF)
|
|
||||||
{
|
|
||||||
if (--open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JSON_HEDLEY_UNLIKELY(!get_cbor_binary_chunk(result)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief narrow a definite CBOR array/map length to std::size_t
|
@brief narrow a definite CBOR array/map length to std::size_t
|
||||||
|
|
||||||
@@ -13164,12 +13078,7 @@ class binary_reader
|
|||||||
{
|
{
|
||||||
result.first = npos; // size
|
result.first = npos; // size
|
||||||
result.second = 0; // type
|
result.second = 0; // type
|
||||||
// seed the flag with the caller's context: inside an ndarray dimension
|
bool is_ndarray = false;
|
||||||
// vector another ndarray is not allowed, and get_ubjson_size_value()
|
|
||||||
// rejects it up front instead of reading it and reporting afterwards.
|
|
||||||
// Seeding it with `false` made every '#' of a "[#[#[..." chain descend
|
|
||||||
// another level, which overflowed the stack (see #5104).
|
|
||||||
bool is_ndarray = inside_ndarray;
|
|
||||||
|
|
||||||
get_ignore_noop();
|
get_ignore_noop();
|
||||||
|
|
||||||
@@ -13202,11 +13111,13 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||||
// an ndarray was read here only if the flag flipped; when it was
|
if (input_format == input_format_t::bjdata && is_ndarray)
|
||||||
// seeded true, get_ubjson_size_value() already rejected the nested
|
|
||||||
// dimension vector
|
|
||||||
if (input_format == input_format_t::bjdata && is_ndarray && !inside_ndarray)
|
|
||||||
{
|
{
|
||||||
|
if (inside_ndarray)
|
||||||
|
{
|
||||||
|
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
||||||
|
exception_message(input_format, "ndarray can not be recursive", "size"), nullptr));
|
||||||
|
}
|
||||||
result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters
|
result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters
|
||||||
}
|
}
|
||||||
return is_error;
|
return is_error;
|
||||||
@@ -13215,7 +13126,7 @@ class binary_reader
|
|||||||
if (current == '#')
|
if (current == '#')
|
||||||
{
|
{
|
||||||
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
|
||||||
if (input_format == input_format_t::bjdata && is_ndarray && !inside_ndarray)
|
if (input_format == input_format_t::bjdata && is_ndarray)
|
||||||
{
|
{
|
||||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
|
||||||
exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
|
||||||
@@ -25064,6 +24975,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
std::swap(m_data.m_type, other.m_data.m_type);
|
std::swap(m_data.m_type, other.m_data.m_type);
|
||||||
std::swap(m_data.m_value, other.m_data.m_value);
|
std::swap(m_data.m_value, other.m_data.m_value);
|
||||||
|
|
||||||
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
|
std::swap(start_position, other.start_position);
|
||||||
|
std::swap(end_position, other.end_position);
|
||||||
|
#endif
|
||||||
|
|
||||||
set_parents();
|
set_parents();
|
||||||
other.set_parents();
|
other.set_parents();
|
||||||
assert_invariant();
|
assert_invariant();
|
||||||
@@ -25990,11 +25906,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in CBOR format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in CBOR format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -26010,11 +25923,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -26039,11 +25949,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in MessagePack format
|
/// @brief create a JSON value from an input in MessagePack format
|
||||||
@@ -26057,11 +25964,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in MessagePack format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in MessagePack format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -26076,11 +25980,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -26103,11 +26004,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in UBJSON format
|
/// @brief create a JSON value from an input in UBJSON format
|
||||||
@@ -26121,11 +26019,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in UBJSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in UBJSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -26140,11 +26035,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -26167,11 +26059,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BJData format
|
/// @brief create a JSON value from an input in BJData format
|
||||||
@@ -26185,11 +26074,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BJData format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in BJData format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -26204,11 +26090,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BSON format
|
/// @brief create a JSON value from an input in BSON format
|
||||||
@@ -26222,11 +26105,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
auto ia = detail::input_adapter(std::forward<InputType>(i));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief create a JSON value from an input in BSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
/// @brief create a JSON value from an input in BSON format (iterator pair, or iterator+sentinel pair for C++20 ranges support)
|
||||||
@@ -26241,11 +26121,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
basic_json result;
|
basic_json result;
|
||||||
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
auto ia = detail::input_adapter(std::move(first), std::move(last));
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -26268,11 +26145,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
auto ia = i.get();
|
auto ia = i.get();
|
||||||
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
detail::json_sax_dom_parser<basic_json, decltype(ia)> sdp(result, allow_exceptions);
|
||||||
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
|
||||||
if (!binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict)) // cppcheck-suppress[accessMoved]
|
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
|
||||||
{
|
return res ? result : basic_json(value_t::discarded);
|
||||||
result = value_t::discarded;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|||||||
@@ -3288,10 +3288,8 @@ TEST_CASE("BJData")
|
|||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR1), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR1), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
||||||
CHECK(json::from_bjdata(vR1, true, false).is_discarded());
|
CHECK(json::from_bjdata(vR1, true, false).is_discarded());
|
||||||
|
|
||||||
// a dimension vector that opens another one is rejected where the
|
|
||||||
// nested '[' is read, rather than after it has been descended into
|
|
||||||
std::vector<uint8_t> const vR2 = {'[', '$', 'i', '#', '[', '#', '[', 'i', 1, ']', ']', 1};
|
std::vector<uint8_t> const vR2 = {'[', '$', 'i', '#', '[', '#', '[', 'i', 1, ']', ']', 1};
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR2), "[json.exception.parse_error.113] parse error at byte 7: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR2), "[json.exception.parse_error.113] parse error at byte 11: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x5D", json::parse_error&);
|
||||||
CHECK(json::from_bjdata(vR2, true, false).is_discarded());
|
CHECK(json::from_bjdata(vR2, true, false).is_discarded());
|
||||||
|
|
||||||
std::vector<uint8_t> const vR3 = {'[', '#', '[', 'i', '2', 'i', 2, ']'};
|
std::vector<uint8_t> const vR3 = {'[', '#', '[', 'i', '2', 'i', 2, ']'};
|
||||||
@@ -3299,7 +3297,7 @@ TEST_CASE("BJData")
|
|||||||
CHECK(json::from_bjdata(vR3, true, false).is_discarded());
|
CHECK(json::from_bjdata(vR3, true, false).is_discarded());
|
||||||
|
|
||||||
std::vector<uint8_t> const vR4 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', 1, ']', 1};
|
std::vector<uint8_t> const vR4 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', 1, ']', 1};
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR4), "[json.exception.parse_error.113] parse error at byte 9: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR4), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
|
||||||
CHECK(json::from_bjdata(vR4, true, false).is_discarded());
|
CHECK(json::from_bjdata(vR4, true, false).is_discarded());
|
||||||
|
|
||||||
std::vector<uint8_t> const vR5 = {'[', '$', 'i', '#', '[', '[', '[', ']', ']', ']'};
|
std::vector<uint8_t> const vR5 = {'[', '$', 'i', '#', '[', '[', '[', ']', ']', ']'};
|
||||||
@@ -3307,25 +3305,12 @@ TEST_CASE("BJData")
|
|||||||
CHECK(json::from_bjdata(vR5, true, false).is_discarded());
|
CHECK(json::from_bjdata(vR5, true, false).is_discarded());
|
||||||
|
|
||||||
std::vector<uint8_t> const vR6 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
|
std::vector<uint8_t> const vR6 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR6), "[json.exception.parse_error.113] parse error at byte 9: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR6), "[json.exception.parse_error.112] parse error at byte 14: syntax error while parsing BJData size: ndarray can not be recursive", json::parse_error&);
|
||||||
CHECK(json::from_bjdata(vR6, true, false).is_discarded());
|
CHECK(json::from_bjdata(vR6, true, false).is_discarded());
|
||||||
|
|
||||||
std::vector<uint8_t> const vH = {'[', 'H', '[', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
|
std::vector<uint8_t> const vH = {'[', 'H', '[', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vH), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vH), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
||||||
CHECK(json::from_bjdata(vH, true, false).is_discarded());
|
CHECK(json::from_bjdata(vH, true, false).is_discarded());
|
||||||
|
|
||||||
// Every "#[" of this chain used to open another dimension vector
|
|
||||||
// and cost several stack frames before anything was rejected, so a
|
|
||||||
// long enough chain crashed the process (see #5104). The nested
|
|
||||||
// vector is refused where it is read, so the length is irrelevant.
|
|
||||||
std::vector<uint8_t> vRdeep = {'['};
|
|
||||||
for (std::size_t i = 0; i < 100000; ++i)
|
|
||||||
{
|
|
||||||
vRdeep.push_back('#');
|
|
||||||
vRdeep.push_back('[');
|
|
||||||
}
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vRdeep), "[json.exception.parse_error.113] parse error at byte 5: syntax error while parsing BJData size: ndarray dimensional vector is not allowed", json::parse_error&);
|
|
||||||
CHECK(json::from_bjdata(vRdeep, true, false).is_discarded());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("objects")
|
SECTION("objects")
|
||||||
|
|||||||
@@ -2035,58 +2035,6 @@ TEST_CASE("CBOR definite length equal to the indefinite-length sentinel")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("CBOR indefinite-length strings do not recurse per chunk")
|
|
||||||
{
|
|
||||||
// Reading an indefinite-length string or byte array used to call itself
|
|
||||||
// once per chunk, so a payload of repeated 0x7F (or 0x5F) bytes exhausted
|
|
||||||
// the call stack before any of the input was rejected. The open levels are
|
|
||||||
// counted now, and the levels below prove the reader still reads the same
|
|
||||||
// values and reports the same errors at the same byte offsets.
|
|
||||||
json _;
|
|
||||||
|
|
||||||
SECTION("many open levels are reported, not crashed on")
|
|
||||||
{
|
|
||||||
const std::vector<uint8_t> input(200000, 0x7F);
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(input), "[json.exception.parse_error.110] parse error at byte 200001: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
|
|
||||||
CHECK(json::from_cbor(input, true, false).is_discarded());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("many open levels are reported, not crashed on (binary)")
|
|
||||||
{
|
|
||||||
const std::vector<uint8_t> input(200000, 0x5F);
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(input), "[json.exception.parse_error.110] parse error at byte 200001: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&);
|
|
||||||
CHECK(json::from_cbor(input, true, false).is_discarded());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("chunks are still concatenated")
|
|
||||||
{
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x7F, 0xFF})) == json(""));
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x7F, 0x61, 0x61, 0xFF})) == json("a"));
|
|
||||||
// nested indefinite-length strings are concatenated across levels
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x7F, 0x7F, 0x61, 0x61, 0xFF, 0x61, 0x62, 0xFF})) == json("ab"));
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x7F, 0x7F, 0x7F, 0x61, 0x7A, 0xFF, 0xFF, 0xFF})) == json("z"));
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0xA1, 0x7F, 0x61, 0x61, 0xFF, 0x01})) == json({{"a", 1}}));
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("chunks are still concatenated (binary)")
|
|
||||||
{
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x5F, 0x41, 0x61, 0xFF})) == json::binary({0x61}));
|
|
||||||
CHECK(json::from_cbor(std::vector<uint8_t>({0x5F, 0x5F, 0x41, 0x61, 0xFF, 0x41, 0x62, 0xFF})) == json::binary({0x61, 0x62}));
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("a chunk that is not a string is still rejected")
|
|
||||||
{
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x7F, 0x7F, 0x00})), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x00", json::parse_error&);
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x5F, 0x5F, 0x00})), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing CBOR binary: expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x00", json::parse_error&);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("a break marker outside an indefinite-length string is not a string")
|
|
||||||
{
|
|
||||||
// 0xFF only closes a string that was opened; on its own it is not one
|
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xA1, 0xFF, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xFF", json::parse_error&);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("CBOR roundtrips" * doctest::skip())
|
TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||||
{
|
{
|
||||||
SECTION("input from flynn")
|
SECTION("input from flynn")
|
||||||
|
|||||||
@@ -1955,3 +1955,80 @@ TEST_CASE("parser class")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("diagnostic positions: value lifetime")
|
||||||
|
{
|
||||||
|
SECTION("copy constructor copies positions, recursively")
|
||||||
|
{
|
||||||
|
const std::string s = R"({"a":1,"b":[1,2,3]})";
|
||||||
|
const json a = json::parse(s);
|
||||||
|
const json b = a; // NOLINT(performance-unnecessary-copy-initialization)
|
||||||
|
|
||||||
|
CHECK(b.start_pos() == a.start_pos());
|
||||||
|
CHECK(b.end_pos() == a.end_pos());
|
||||||
|
CHECK(b["b"].start_pos() == a["b"].start_pos());
|
||||||
|
CHECK(b["b"].end_pos() == a["b"].end_pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("move constructor resets the moved-from value to npos")
|
||||||
|
{
|
||||||
|
const std::string s = R"({"a":1,"b":[1,2,3]})";
|
||||||
|
json a = json::parse(s);
|
||||||
|
const auto a_start = a.start_pos();
|
||||||
|
const auto a_end = a.end_pos();
|
||||||
|
|
||||||
|
const json b(std::move(a));
|
||||||
|
|
||||||
|
CHECK(b.start_pos() == a_start);
|
||||||
|
CHECK(b.end_pos() == a_end);
|
||||||
|
|
||||||
|
CHECK(a.start_pos() == std::string::npos); // NOLINT(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
|
||||||
|
CHECK(a.end_pos() == std::string::npos); // NOLINT(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("swap() exchanges positions along with the values")
|
||||||
|
{
|
||||||
|
// basic_json::swap() (and the friend swap() that forwards to it) used
|
||||||
|
// to swap only m_data.m_type/m_data.m_value, leaving
|
||||||
|
// start_position/end_position untouched -- unlike copy-assignment's
|
||||||
|
// operator=(basic_json), which swaps positions as part of its
|
||||||
|
// copy-and-swap implementation. After swap(a, b), each value ended up
|
||||||
|
// with the *other* value's content but its *own* original position.
|
||||||
|
// This is now fixed so that swap() is consistent with copy-assignment.
|
||||||
|
json a = json::parse(R"({"a":1})");
|
||||||
|
json b = json::parse(R"([1,2,3,4,5])");
|
||||||
|
const auto a_start = a.start_pos();
|
||||||
|
const auto a_end = a.end_pos();
|
||||||
|
const auto b_start = b.start_pos();
|
||||||
|
const auto b_end = b.end_pos();
|
||||||
|
// lengths (and thus end positions) differ, which is enough to tell
|
||||||
|
// after the swap whether positions actually moved with the values
|
||||||
|
CHECK(a_end != b_end);
|
||||||
|
|
||||||
|
using std::swap;
|
||||||
|
swap(a, b);
|
||||||
|
|
||||||
|
CHECK(a == json::parse(R"([1,2,3,4,5])"));
|
||||||
|
CHECK(b == json::parse(R"({"a":1})"));
|
||||||
|
|
||||||
|
CHECK(a.start_pos() == b_start);
|
||||||
|
CHECK(a.end_pos() == b_end);
|
||||||
|
CHECK(b.start_pos() == a_start);
|
||||||
|
CHECK(b.end_pos() == a_end);
|
||||||
|
|
||||||
|
// member swap() behaves the same as the free function
|
||||||
|
json c = json::parse(R"({"a":1})");
|
||||||
|
json d = json::parse(R"([1,2,3,4,5])");
|
||||||
|
const auto c_start = c.start_pos();
|
||||||
|
const auto c_end = c.end_pos();
|
||||||
|
const auto d_start = d.start_pos();
|
||||||
|
const auto d_end = d.end_pos();
|
||||||
|
|
||||||
|
c.swap(d);
|
||||||
|
|
||||||
|
CHECK(c.start_pos() == d_start);
|
||||||
|
CHECK(c.end_pos() == d_end);
|
||||||
|
CHECK(d.start_pos() == c_start);
|
||||||
|
CHECK(d.end_pos() == c_end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user