Skip to content

Commit 828bc55

Browse files
committed
Address review: clarify test naming and NEWS wording
- Rename bad_expected_names -> mojibake_expected_names in the append / comment tests. - The comment on newname2 was potentially misleading: it is representable in cp437 but is still stored as UTF-8 (new entries default to UTF-8 flag). - Reword the NEWS entry.
1 parent 7d3a02f commit 828bc55

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

Lib/test/test_zipfile/test_core.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,20 +3639,20 @@ def test_read_with_unsuitable_metadata_encoding(self):
36393639

36403640
def test_read_after_append(self):
36413641
newname = '\u56db' # Han 'four'
3642-
newname2 = 'fünf' # encodeable in cp437
3642+
newname2 = 'fünf' # representable in cp437, but still stored as UTF-8
36433643
expected_names = [*self.file_names, newname, newname2]
3644-
bad_expected_names = [name.encode('shift_jis').decode('cp437')
3645-
if i < 2 else name
3646-
for i, name in enumerate(expected_names)]
3644+
mojibake_expected_names = [name.encode('shift_jis').decode('cp437')
3645+
if i < 2 else name
3646+
for i, name in enumerate(expected_names)]
36473647
expected_content = (*self.file_content, b"newcontent", b"newcontent2")
36483648

36493649
with zipfile.ZipFile(TESTFN, "a") as zipfp:
36503650
zipfp.writestr(newname, "newcontent")
36513651
zipfp.writestr(newname2, "newcontent2")
3652-
self.assertEqual(sorted(zipfp.namelist()), sorted(bad_expected_names))
3652+
self.assertEqual(sorted(zipfp.namelist()), sorted(mojibake_expected_names))
36533653

36543654
with zipfile.ZipFile(TESTFN, "r") as zipfp:
3655-
self._test_read(zipfp, bad_expected_names, expected_content)
3655+
self._test_read(zipfp, mojibake_expected_names, expected_content)
36563656

36573657
with zipfile.ZipFile(TESTFN, "r", metadata_encoding='shift_jis') as zipfp:
36583658
self._test_read(zipfp, expected_names, expected_content)
@@ -3666,14 +3666,14 @@ def test_write_with_metadata_encoding(self):
36663666

36673667
def test_add_comment(self):
36683668
with zipfile.ZipFile(TESTFN, "r") as zipfp:
3669-
bad_expected_names = zipfp.namelist()
3669+
mojibake_expected_names = zipfp.namelist()
36703670

36713671
with zipfile.ZipFile(TESTFN, "a") as zipfp:
36723672
zipfp.comment = b'comment'
3673-
self.assertEqual(zipfp.namelist(), bad_expected_names)
3673+
self.assertEqual(zipfp.namelist(), mojibake_expected_names)
36743674

36753675
with zipfile.ZipFile(TESTFN, "r") as zipfp:
3676-
self._test_read(zipfp, bad_expected_names, self.file_content)
3676+
self._test_read(zipfp, mojibake_expected_names, self.file_content)
36773677

36783678
with zipfile.ZipFile(TESTFN, "r", metadata_encoding='shift_jis') as zipfp:
36793679
self._test_read(zipfp, self.file_names, self.file_content)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
Preserve non-ASCII filenames encoded not in UTF-8 when appending to
2-
:class:`zipfile.ZipFile`.
1+
Preserve non-UTF-8 encoded filenames when appending to a
2+
:class:`zipfile.ZipFile`. Previously, names stored in a legacy encoding
3+
(without the UTF-8 flag bit set) were corrupted when the central directory
4+
was rewritten.

0 commit comments

Comments
 (0)