Skip to content

Commit

Permalink
Expand the UTF16_win test to verify that actual UTF-8 is getting stor…
Browse files Browse the repository at this point in the history
…ed in the archive
  • Loading branch information
kientzle committed Jul 6, 2024
1 parent 14ab10b commit a5992a5
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions libarchive/test/test_pax_filename_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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
}

Expand Down

0 comments on commit a5992a5

Please sign in to comment.