utf8_to_wstrbuf now handles invalid utf8 sequences (#3244)

This commit is contained in:
captainurist
2024-11-06 04:54:01 +08:00
committed by GitHub
parent 63f0875000
commit 5673e9e545
3 changed files with 22 additions and 3 deletions

View File

@@ -167,3 +167,21 @@ TEST_CASE("default logger API", "[default logger]") {
spdlog::drop_all();
spdlog::set_pattern("%v");
}
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
TEST_CASE("utf8 to utf16 conversion using windows api", "[windows utf]") {
spdlog::wmemory_buf_t buffer;
spdlog::details::os::utf8_to_wstrbuf("", buffer);
REQUIRE(buffer.data() == std::wstring(L""));
spdlog::details::os::utf8_to_wstrbuf("abc", buffer);
REQUIRE(buffer.data() == std::wstring(L"abc"));
spdlog::details::os::utf8_to_wstrbuf("\xc3\x28", buffer); // Invalid UTF-8 sequence.
REQUIRE(buffer.data() == std::wstring(L"\xfffd("));
spdlog::details::os::utf8_to_wstrbuf("\xe3\x81\xad\xe3\x81\x93", buffer); // "Neko" in hiragana.
REQUIRE(buffer.data() == std::wstring(L"\x306d\x3053"));
}
#endif