Backport commit 33543b4e0e5d from Python 3.2: #10801: In zipfile, support

different encodings for the header and the filenames.  Patch by MvL, test by
Eli Bendersky.
This commit is contained in:
Victor Stinner 2011-05-18 13:43:23 +02:00
parent 02a67ac72b
commit ff1d2f4cc5
3 changed files with 36 additions and 4 deletions

View file

@ -928,7 +928,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:
raise BadZipfile(
'File name in directory %r and header %r differ.'
% (zinfo.orig_filename, fname))