feat(data,text,testing): implement VL-002 TOML, VL-008 StrictJson UTF-8, VL-009 native tests, and VL-013 Semver shorthands
This commit is contained in:
1 parent
53d42bda42
commit
adfc8548dc
11 files changed
+2888
-28
No files matched your search
@@ -152,3 +152,69 @@ Void::Testing::Test strict_json_decodes_valid_unicode_pairs()
|
||||
Void::Testing::expect(
|
||||
!Void::Json::Strict::parse(R"("\uD83D")").has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test strict_json_validates_utf8_in_parse_and_serialize()
|
||||
{
|
||||
// Valid 1, 2, 3, and 4-byte scalars including boundaries U+D7FF, U+E000, U+10FFFF
|
||||
const std::string valid_json =
|
||||
std::string{R"({"ascii":"hello","latin":")"} + "\xC3\xA9" +
|
||||
R"(","euro":")" + "\xE2\x82\xAC" + R"(","emoji":")" +
|
||||
"\xF0\x9F\x98\x80" + R"(","hi_bmp":")" + "\xED\x9F\xBF" +
|
||||
R"(","priv":")" + "\xEE\x80\x80" + R"(","max_cp":")" +
|
||||
"\xF4\x8F\xBF\xBF" + R"("})";
|
||||
|
||||
const auto parsed = Void::Json::Strict::parse(valid_json);
|
||||
Void::Testing::require(parsed.has_value());
|
||||
const auto serialized = Void::Json::Strict::serialize(*parsed);
|
||||
Void::Testing::require(serialized.has_value());
|
||||
const auto reparsed = Void::Json::Strict::parse(*serialized);
|
||||
Void::Testing::require(reparsed.has_value());
|
||||
|
||||
// Invalid UTF-8 sequences in string values and object keys
|
||||
const std::array<std::string, 10> invalid_payloads{
|
||||
std::string{"\"\xFF\""}, // invalid lead 0xFF
|
||||
std::string{"\"\x80\""}, // stray continuation byte
|
||||
std::string{"\"\xBF\""}, // stray continuation byte
|
||||
std::string{"\"\xC0\xAF\""}, // overlong 2-byte '/'
|
||||
std::string{"\"\xC1\x81\""}, // overlong 2-byte 'A'
|
||||
std::string{"\"\xE0\x9F\x80\""}, // overlong 3-byte
|
||||
std::string{"\"\xED\xA0\x80\""}, // UTF-8 encoded U+D800
|
||||
std::string{"\"\xED\xBF\xBF\""}, // UTF-8 encoded U+DFFF
|
||||
std::string{"\"\xF4\x90\x80\x80\""}, // > U+10FFFF (U+110000)
|
||||
std::string{"{\"\xFF\":\"val\"}"}, // invalid UTF-8 in object key
|
||||
};
|
||||
for (const auto& payload : invalid_payloads) {
|
||||
const auto res = Void::Json::Strict::parse(payload);
|
||||
Void::Testing::expect(!res.has_value());
|
||||
Void::Testing::expect(!Void::Json::Strict::is_valid_utf8(payload));
|
||||
}
|
||||
|
||||
// Truncated multi-byte sequences inside strings
|
||||
Void::Testing::expect(
|
||||
!Void::Json::Strict::parse(std::string{"\"\xC3\""}).has_value());
|
||||
Void::Testing::expect(
|
||||
!Void::Json::Strict::parse(std::string{"\"\xF0\x9F\x98\""})
|
||||
.has_value());
|
||||
|
||||
// Serialization must also reject corrupt UTF-8 in Values or keys
|
||||
const Void::Json::Strict::Value bad_val{std::string{"ok\xED\xA0\x80"}};
|
||||
Void::Testing::expect(
|
||||
!Void::Json::Strict::serialize(bad_val).has_value());
|
||||
|
||||
Void::Json::Strict::Value::Object bad_key_obj;
|
||||
bad_key_obj.emplace(std::string{"bad\xFFkey"},
|
||||
Void::Json::Strict::Value{1});
|
||||
Void::Testing::expect(
|
||||
!Void::Json::Strict::serialize(
|
||||
Void::Json::Strict::Value{std::move(bad_key_obj)})
|
||||
.has_value());
|
||||
|
||||
// Control char escaping & round-trip in serialize()
|
||||
const Void::Json::Strict::Value ctrl{std::string{"a\nb\tc\x01\"\\"}};
|
||||
const auto escaped = Void::Json::Strict::serialize(ctrl);
|
||||
Void::Testing::require(escaped.has_value());
|
||||
const auto ctrl_back = Void::Json::Strict::parse(*escaped);
|
||||
Void::Testing::require(ctrl_back.has_value());
|
||||
Void::Testing::expect_eq(std::get<std::string>(ctrl_back->value),
|
||||
std::string{"a\nb\tc\x01\"\\"});
|
||||
}
|
||||
Reference in new issue
Block a user