diff options
author | Yeojin Kim <yeojin.dev@gmail.com> | 2023-04-05 11:54:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-05 11:54:48 (GMT) |
commit | 8f70b16e3397ad32757ddbabd5180cbef0036a4b (patch) | |
tree | b54ae17f463b5a0cb149acac1b35977f9df9ca37 /Lib/test/test_zipfile | |
parent | a28d4edb23b7150942f1eceb9e97c6f53aa4de42 (diff) | |
download | cpython-8f70b16e3397ad32757ddbabd5180cbef0036a4b.zip cpython-8f70b16e3397ad32757ddbabd5180cbef0036a4b.tar.gz cpython-8f70b16e3397ad32757ddbabd5180cbef0036a4b.tar.bz2 |
gh-86094: Add support for Unicode Path Extra Field in ZipFile (gh-102566)
Diffstat (limited to 'Lib/test/test_zipfile')
-rw-r--r-- | Lib/test/test_zipfile/test_core.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index e23f5c2..73c6b01 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -1616,6 +1616,33 @@ class OtherTests(unittest.TestCase): self.assertEqual(zf.filelist[0].filename, "foo.txt") self.assertEqual(zf.filelist[1].filename, "\xf6.txt") + @requires_zlib() + def test_read_zipfile_containing_unicode_path_extra_field(self): + with zipfile.ZipFile(TESTFN, mode='w') as zf: + # create a file with a non-ASCII name + filename = '이름.txt' + filename_encoded = filename.encode('utf-8') + + # create a ZipInfo object with Unicode path extra field + zip_info = zipfile.ZipInfo(filename) + + tag_for_unicode_path = b'\x75\x70' + version_of_unicode_path = b'\x01' + + import zlib + filename_crc = struct.pack('<L', zlib.crc32(filename_encoded)) + + extra_data = version_of_unicode_path + filename_crc + filename_encoded + tsize = len(extra_data).to_bytes(2, 'little') + + zip_info.extra = tag_for_unicode_path + tsize + extra_data + + # add the file to the ZIP archive + zf.writestr(zip_info, b'Hello World!') + + with zipfile.ZipFile(TESTFN, "r") as zf: + self.assertEqual(zf.filelist[0].filename, "이름.txt") + def test_read_after_write_unicode_filenames(self): with zipfile.ZipFile(TESTFN2, 'w') as zipfp: zipfp.writestr('приклад', b'sample') |