[libc++][test] Don't pass ill-formed UTF-8 to MAKE_STRING_VIEW (#136403)

This commit is contained in:
S. B. Tam
2025-06-19 15:21:28 +08:00
committed by GitHub
parent 3e795c60c7
commit a9a71b6d31
2 changed files with 25 additions and 15 deletions

View File

@@ -337,7 +337,7 @@ void test_string() {
// Ill-formed // Ill-formed
if constexpr (sizeof(CharT) == 1) if constexpr (sizeof(CharT) == 1)
test_format(SV(R"("\x{80}")"), SV("{:?}"), SV("\x80")); test_format(SV(R"("\x{80}")"), SV("{:?}"), "\x80");
// *** P2713R1 examples *** // *** P2713R1 examples ***
test_format(SV(R"(["\u{301}"])"), SV("[{:?}]"), SV("\u0301")); test_format(SV(R"(["\u{301}"])"), SV("[{:?}]"), SV("\u0301"));

View File

@@ -75,30 +75,40 @@ void test() {
// Invalid Unicode Scalar Values // Invalid Unicode Scalar Values
if constexpr (std::same_as<CharT, char>) { if constexpr (std::same_as<CharT, char>) {
check_exception("The format specifier contains malformed Unicode characters", SV("{:\xed\xa0\x80^}"), 42); // U+D800 check_exception("The format specifier contains malformed Unicode characters",
check_exception("The format specifier contains malformed Unicode characters", SV("{:\xed\xa0\xbf^}"), 42); // U+DBFF std::string_view{"{:\xed\xa0\x80^}"},
check_exception("The format specifier contains malformed Unicode characters", SV("{:\xed\xbf\x80^}"), 42); // U+DC00 42); // U+D800
check_exception("The format specifier contains malformed Unicode characters", SV("{:\xed\xbf\xbf^}"), 42); // U+DFFF check_exception("The format specifier contains malformed Unicode characters",
std::string_view{"{:\xed\xa0\xbf^}"},
check_exception( 42); // U+DBFF
"The format specifier contains malformed Unicode characters", SV("{:\xf4\x90\x80\x80^}"), 42); // U+110000 check_exception("The format specifier contains malformed Unicode characters",
check_exception( std::string_view{"{:\xed\xbf\x80^}"},
"The format specifier contains malformed Unicode characters", SV("{:\xf4\x90\xbf\xbf^}"), 42); // U+11FFFF 42); // U+DC00
check_exception("The format specifier contains malformed Unicode characters",
std::string_view{"{:\xed\xbf\xbf^}"},
42); // U+DFFF
check_exception("The format specifier contains malformed Unicode characters", check_exception("The format specifier contains malformed Unicode characters",
SV("{:\x80^}"), std::string_view{"{:\xf4\x90\x80\x80^}"},
42); // U+110000
check_exception("The format specifier contains malformed Unicode characters",
std::string_view{"{:\xf4\x90\xbf\xbf^}"},
42); // U+11FFFF
check_exception("The format specifier contains malformed Unicode characters",
std::string_view{"{:\x80^}"},
42); // Trailing code unit with no leading one. 42); // Trailing code unit with no leading one.
check_exception("The format specifier contains malformed Unicode characters", check_exception("The format specifier contains malformed Unicode characters",
SV("{:\xc0^}"), std::string_view{"{:\xc0^}"},
42); // Missing trailing code unit. 42); // Missing trailing code unit.
check_exception("The format specifier contains malformed Unicode characters", check_exception("The format specifier contains malformed Unicode characters",
SV("{:\xe0\x80^}"), std::string_view{"{:\xe0\x80^}"},
42); // Missing trailing code unit. 42); // Missing trailing code unit.
check_exception("The format specifier contains malformed Unicode characters", check_exception("The format specifier contains malformed Unicode characters",
SV("{:\xf0\x80^}"), std::string_view{"{:\xf0\x80^}"},
42); // Missing two trailing code units. 42); // Missing two trailing code units.
check_exception("The format specifier contains malformed Unicode characters", check_exception("The format specifier contains malformed Unicode characters",
SV("{:\xf0\x80\x80^}"), std::string_view{"{:\xf0\x80\x80^}"},
42); // Missing trailing code unit. 42); // Missing trailing code unit.
#ifndef TEST_HAS_NO_WIDE_CHARACTERS #ifndef TEST_HAS_NO_WIDE_CHARACTERS