diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 28e62dc5c61c50..e2e37a17704185 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1589,6 +1589,11 @@ def test_write_unicode_filenames(self): self.assertEqual(zf.filelist[0].filename, "foo.txt") self.assertEqual(zf.filelist[1].filename, "\xf6.txt") + def test_read_after_write_unicode_filenames(self): + with zipfile.ZipFile(TESTFN2, 'w') as zipfp: + zipfp.writestr('приклад', b'sample') + self.assertEqual(zipfp.read('приклад'), b'sample') + def test_exclusive_create_zip_file(self): """Test exclusive creating a new zipfile.""" unlink(TESTFN2) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index f7a2a2e8b8ab9a..73e89666309ffe 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1546,7 +1546,7 @@ def open(self, name, mode="r", pwd=None, *, force_zip64=False): # strong encryption raise NotImplementedError("strong encryption (flag bit 6)") - if zinfo.flag_bits & 0x800: + if fheader[_FH_GENERAL_PURPOSE_FLAG_BITS] & 0x800: # UTF-8 filename fname_str = fname.decode("utf-8") else: diff --git a/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst b/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst new file mode 100644 index 00000000000000..20580c7886fac5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst @@ -0,0 +1,2 @@ +Fixed reading files with non-ASCII names from ZIP archive directly after +writing them.