Fix formatting of paths containing invalid Unicode

This commit is contained in:
Victor Zverovich
2023-05-07 08:05:28 -07:00
parent dde8cf3bb7
commit 1e0ce567ef
2 changed files with 9 additions and 12 deletions

View File

@@ -2027,7 +2027,6 @@ auto write_escaped_cp(OutputIt out, const find_escape_result<Char>& escape)
*out++ = static_cast<Char>('\\'); *out++ = static_cast<Char>('\\');
break; break;
default: default:
if (is_utf8()) {
if (escape.cp < 0x100) { if (escape.cp < 0x100) {
return write_codepoint<2, Char>(out, 'x', escape.cp); return write_codepoint<2, Char>(out, 'x', escape.cp);
} }
@@ -2037,7 +2036,6 @@ auto write_escaped_cp(OutputIt out, const find_escape_result<Char>& escape)
if (escape.cp < 0x110000) { if (escape.cp < 0x110000) {
return write_codepoint<8, Char>(out, 'U', escape.cp); return write_codepoint<8, Char>(out, 'U', escape.cp);
} }
}
for (Char escape_char : basic_string_view<Char>( for (Char escape_char : basic_string_view<Char>(
escape.begin, to_unsigned(escape.end - escape.begin))) { escape.begin, to_unsigned(escape.end - escape.begin))) {
out = write_codepoint<2, Char>(out, 'x', out = write_codepoint<2, Char>(out, 'x',

View File

@@ -30,8 +30,7 @@ TEST(std_test, path) {
L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448" L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448"
L"\x0447\x044B\x043D\x0430")), L"\x0447\x044B\x043D\x0430")),
"\"Шчучыншчына\""); "\"Шчучыншчына\"");
// EXPECT_EQ(fmt::format("{}", std::filesystem::path(L"\xd800")), EXPECT_EQ(fmt::format("{}", std::filesystem::path(L"\xd800")), "\"\\ud800\"");
// "\\x{d800}");
# endif # endif
} }