diff --git a/libarchive/test/test_pax_filename_encoding.c b/libarchive/test/test_pax_filename_encoding.c index 3165b65dd3..0c264a341a 100644 --- a/libarchive/test/test_pax_filename_encoding.c +++ b/libarchive/test/test_pax_filename_encoding.c @@ -592,6 +592,7 @@ DEFINE_TEST(test_pax_filename_encoding_UTF16_win) struct archive *a; struct archive_entry *entry; char buff[0x2000]; + char *p; size_t used; /* @@ -608,11 +609,9 @@ DEFINE_TEST(test_pax_filename_encoding_UTF16_win) archive_write_free(a); return; } - - /* Re-create a write archive object since filenames should be written - * in UTF-8 by default. */ archive_write_free(a); + /* Create a new archive handle with default charset handling */ a = archive_write_new(); assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a)); assertEqualInt(ARCHIVE_OK, @@ -650,6 +649,27 @@ DEFINE_TEST(test_pax_filename_encoding_UTF16_win) archive_entry_free(entry); assertEqualInt(ARCHIVE_OK, archive_write_free(a)); + /* Verify the bytes of the file directly to ensure the + * filenames were encoded the way we expect. */ + + p = buffer + 0; /* First header */ + assertEqualString(p + 0, "\xE4\xBD\xA0\xE5\xA5\xBD.txt"); + assertEqualInt(p[156], '0'); /* Regular file */ + + p += 512; /* Second header */ + assertEqualString(p + 0, "\xD0\xBF\xD1\x80\xD0\xB8/"); + assertEqualInt(p[156], '5'); /* directory */ + + p += 512; /* Third header */ + assertEqualString(p + 0, "\xE5\x86\x8D\xE8\xA7\x81.txt"); + assertEqualInt(p[156], '2'); /* symlink */ + assertEqualString(p + 157, "\xE6\x99\x9A\xE5\xAE\x89.txt"); /* link name */ + + p += 512; /* Fourth header */ + assertEqualString(p + 0, "\xE6\x99\x9A\xE5\xAE\x89.txt"); + assertEqualInt(p[156], '1'); /* hard link */ + assertEqualString(p + 157, "\xE6\x99\x9A\xE5\xAE\x89.txt"); /* link name */ + /* Ensure that the names round trip properly */ a = archive_read_new(); archive_read_support_format_all(a); @@ -673,6 +693,8 @@ DEFINE_TEST(test_pax_filename_encoding_UTF16_win) assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &entry)); assertEqualWString(L"\u665a\u5b89.txt", archive_entry_pathname_w(entry)); assertEqualWString(L"\u4f60\u597d.txt", archive_entry_hardlink_w(entry)); + + archive_free(a); #endif }