mirror of
https://github.com/nlohmann/json.git
synced 2025-07-25 13:41:56 +03:00
💥 CBOR/MessagePack input must end with EOF #505
The CBOR and MessagePack parsers now expect the input to be read until the end. Unless the new parameter "strict" is set to false (it is true by default), an exception is raised if the parser ends prematurely. This is a breaking change as the parsers ignored unread input so far. Furthermore, the offset/startIndex paramter introduced in #462 was removed as this behavior can be mimicked with an iterator range. For instance, instead of calling "from_cbor(vec, 5);", you can write "from_cbor({vec.begin()+5, vec.end()});".
This commit is contained in:
@ -1101,6 +1101,23 @@ TEST_CASE("MessagePack")
|
||||
CHECK_THROWS_WITH(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})),
|
||||
"[json.exception.parse_error.113] parse error at 2: expected a MessagePack string; last byte: 0xff");
|
||||
}
|
||||
|
||||
SECTION("strict mode")
|
||||
{
|
||||
std::vector<uint8_t> vec = {0xc0, 0xc0};
|
||||
SECTION("non-strict mode")
|
||||
{
|
||||
const auto result = json::from_msgpack(vec, false);
|
||||
CHECK(result == json());
|
||||
}
|
||||
|
||||
SECTION("strict mode")
|
||||
{
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec), json::parse_error);
|
||||
CHECK_THROWS_WITH(json::from_msgpack(vec),
|
||||
"[json.exception.parse_error.110] parse error at 2: expected end of input");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1147,7 +1164,7 @@ TEST_CASE("single MessagePack roundtrip")
|
||||
|
||||
// check with different start index
|
||||
packed.insert(packed.begin(), 5, 0xff);
|
||||
CHECK(j1 == json::from_msgpack(packed, 5));
|
||||
CHECK(j1 == json::from_msgpack({packed.begin() + 5, packed.end()}));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user