if (sc == NULL)
return (-1);/* Couldn't allocate memory for sc. */
r = archive_strcpy_l(&(aes->aes_mbs), utf8, sc);
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* On failure, make an effort to convert UTF8 to WCS as the active code page
+ * may not be able to represent all characters in the string */
+ if (r != 0) {
+ if (archive_wstring_append_from_mbs_in_codepage(&(aes->aes_wcs),
+ aes->aes_utf8.s, aes->aes_utf8.length, sc) == 0)
+ aes->aes_set = AES_SET_UTF8 | AES_SET_WCS;
+ }
+#endif
+
if (a == NULL)
free_sconv_object(sc);
if (r != 0)
EPILOGUE();
}
+DEFINE_TEST(test_read_format_rar5_unicode)
+{
+#if !defined(WIN32) || defined(__CYGWIN__)
+ skipping("Skipping test on non-Windows");
+ return;
+#else
+ /* Corresponds to the names:
+ * ๐๐.txt
+ * ๐ฎ๐๐๐ท๐๐๐พ๐ธ ๐ฟ๐พ๐๐.txt
+ * โฝโโกโ โโโโ.txt */
+ const wchar_t* emoji_name = L"\U0001f44b\U0001f30e.txt";
+ const wchar_t* italic_name = L"\U0001d4ae\U0001d4ce\U0001d4c2\U0001d4b7\U0001d45c\U0001d4c1\U0001d4be\U0001d4b8 \U0001d43f\U0001d4be\U0001d4c3\U0001d4c0.txt";
+ const wchar_t* circle_name = L"\u24bd\u24d0\u24e1\u24d3 \u24c1\u24d8\u24dd\u24da.txt";
+
+ PROLOGUE("test_read_format_rar5_unicode.rar");
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualWString(emoji_name, archive_entry_pathname_w(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualWString(circle_name, archive_entry_pathname_w(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
+ assertEqualWString(emoji_name, archive_entry_hardlink_w(ae));
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualWString(italic_name, archive_entry_pathname_w(ae));
+ assertEqualInt(archive_entry_mode(ae), AE_IFLNK | 0644);
+ assertEqualWString(emoji_name, archive_entry_symlink_w(ae));
+ EPILOGUE();
+#endif
+}
+
DEFINE_TEST(test_read_format_rar5_block_by_block)
{
/* This test uses strange buffer sizes intentionally. */
--- /dev/null
+begin 0744 test_read_format_rar5_unicode.rar\r
+M4F%R(1H'`0#SX8+K"P$%!P`&`0&`@(``//TR$"@"`PN-``2-`"#FQN;K@```\r
+M#/"?D8OPGXR.+G1X=`H#`D:)>%;RZ]D!2&5L;&\L('=O<FQD(2/9BPA(`@,<\r
+M``0-(`````"````=XI*]XI.0XI.AXI.3(.*3@>*3F.*3G>*3FBYT>'0*`P)&\r
+MB7A6\NO9`1`%!``,\)^1B_"?C(XN='ATD-'.1V$"`QP`!`"@"`````"````U\r
+M\)V2KO"=DX[PG9."\)V2M_"=D9SPG9.!\)V2OO"=DK@@\)V0O_"=DK[PG9.#\r
+L\)V3@"YT>'0*`P(>7'J>!.S9`1`%`@`,\)^1B_"?C(XN='AT'7=640,%!```\r
+`\r
+end\r