Merge pull request #2308 from nlohmann/cbor_tags
Fix bug in CBOR tag handling
This commit is contained in:
commit
40b78d3847
3 changed files with 73 additions and 44 deletions
|
@ -2705,4 +2705,25 @@ TEST_CASE("Tagged values")
|
|||
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("tagged binary")
|
||||
{
|
||||
// create a binary value of subtype 42
|
||||
json j;
|
||||
j["binary"] = json::binary({0xCA, 0xFE, 0xBA, 0xBE}, 42);
|
||||
|
||||
// convert to CBOR
|
||||
const auto v = json::to_cbor(j);
|
||||
CHECK(v == std::vector<std::uint8_t> {0xA1, 0x66, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0xD8, 0x2A, 0x44, 0xCA, 0xFE, 0xBA, 0xBE});
|
||||
|
||||
// parse error when parsing tagged value
|
||||
CHECK_THROWS_AS(json::from_cbor(v), json::parse_error);
|
||||
CHECK_THROWS_WITH(json::from_cbor(v), "[json.exception.parse_error.112] parse error at byte 9: syntax error while parsing CBOR value: invalid byte: 0xD8");
|
||||
|
||||
// binary without subtype when tags are ignored
|
||||
json jb = json::from_cbor(v, true, true, json::cbor_tag_handler_t::ignore);
|
||||
CHECK(jb.is_object());
|
||||
CHECK(jb["binary"].is_binary());
|
||||
CHECK(!jb["binary"].get_binary().has_subtype());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue