summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-01-01 10:09:32 (GMT)
committerGeorg Brandl <georg@python.org>2011-01-01 10:09:32 (GMT)
commit5ba11de8454b7dbc1cf260911a2628608267a50c (patch)
tree1677c9be0261289540532af66acd17d8b663a36a /Lib
parentd30a0dd681d82251dc3611c49d6a2d9ce2e48e5c (diff)
downloadcpython-5ba11de8454b7dbc1cf260911a2628608267a50c.zip
cpython-5ba11de8454b7dbc1cf260911a2628608267a50c.tar.gz
cpython-5ba11de8454b7dbc1cf260911a2628608267a50c.tar.bz2
#10801: In zipfile, support different encodings for the header and the filenames. Patch by MvL, test by Eli Bendersky.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_zipfile.py14
-rw-r--r--Lib/test/zip_cp437_header.zipbin0 -> 270 bytes
-rw-r--r--Lib/zipfile.py8
3 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index d90e771..e8aec4f 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -6,6 +6,7 @@ except ImportError:
import io
import os
+import sys
import imp
import time
import shutil
@@ -23,6 +24,7 @@ from test.support import TESTFN, run_unittest, findfile, unlink
TESTFN2 = TESTFN + "2"
TESTFNDIR = TESTFN + "d"
FIXEDTEST_SIZE = 1000
+DATAFILES_DIR = 'zipfile_datafiles'
SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
('ziptest2dir/_ziptest2', 'qawsedrftg'),
@@ -487,6 +489,18 @@ class TestsWithSourceFile(unittest.TestCase):
except zipfile.BadZipFile:
self.assertTrue(zipfp2.fp is None, 'zipfp is not closed')
+ def test_unicode_filenames(self):
+ if __name__ == '__main__':
+ myfile = sys.argv[0]
+ else:
+ myfile = __file__
+
+ mydir = os.path.dirname(myfile) or os.curdir
+ fname = os.path.join(mydir, 'zip_cp437_header.zip')
+
+ with zipfile.ZipFile(fname) as zipfp:
+ zipfp.extractall()
+
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
diff --git a/Lib/test/zip_cp437_header.zip b/Lib/test/zip_cp437_header.zip
new file mode 100644
index 0000000..f7c6cf1
--- /dev/null
+++ b/Lib/test/zip_cp437_header.zip
Binary files differ
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 197f0bc..50f4848 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -930,7 +930,13 @@ class ZipFile:
if fheader[_FH_EXTRA_FIELD_LENGTH]:
zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH])
- if fname != zinfo.orig_filename.encode("utf-8"):
+ if zinfo.flag_bits & 0x800:
+ # UTF-8 filename
+ fname_str = fname.decode("utf-8")
+ else:
+ fname_str = fname.decode("cp437")
+
+ if fname_str != zinfo.orig_filename:
if not self._filePassed:
zef_file.close()
raise BadZipFile(