diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index 5e098720df77010..69203142f61589f 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -4539,6 +4539,66 @@ def test_empty_zipfile(self): self.fail("Unable to create empty ZIP file in 'a' mode") zipf.close() + def test_append_preserves_ascii_utf8_flag(self): + comments = (b'', 'caf\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')) + updates = ( + ('append', lambda zf: zf.writestr('added.txt', b'added')), + ('comment', lambda zf: setattr(zf, 'comment', b'archive comment')), + ) + for comment, (operation, update) in itertools.product(comments, updates): + with self.subTest(comment=comment, operation=operation): + stream = io.BytesIO() + with zipfile.ZipFile(stream, 'w') as archive: + entry = zipfile.ZipInfo('file.txt') + entry.comment = comment + archive.writestr(entry, b'payload') + original = bytearray(stream.getvalue()) + central_offset = original.index(b'PK\x01\x02') + struct.pack_into('