EPUB Input: When extracting the contents of epub files on windows, do not error out if one or more of the components in the epub file have filepaths containing characters that are invalid for the windows filesystem, instead, just replace those characters, since those entries are likely to be bugs in the zip container anyway. Fixes #950081 (Private bug)

This commit is contained in:
Kovid Goyal 2012-03-09 22:07:18 +05:30
parent 5844ecb1e1
commit 0d8d44567b

View File

@ -1097,18 +1097,26 @@ class ZipFile:
and len(os.path.splitdrive(targetpath)[1]) > 1):
targetpath = targetpath[:-1]
# don't include leading "/" from file name if present
if member.filename[0] == '/':
targetpath = os.path.join(targetpath, member.filename[1:])
else:
targetpath = os.path.join(targetpath, member.filename)
base_target = targetpath # Added by Kovid
targetpath = os.path.normpath(targetpath)
# don't include leading "/" from file name if present
fname = member.filename
if fname.startswith('/'):
fname = fname[1:]
targetpath = os.path.normpath(os.path.join(base_target, fname))
# Create all upper directories if necessary.
upperdirs = os.path.dirname(targetpath)
if upperdirs and not os.path.exists(upperdirs):
os.makedirs(upperdirs)
try:
os.makedirs(upperdirs)
except: # Added by Kovid
targetpath = os.path.join(base_target,
sanitize_file_name2(fname))
upperdirs = os.path.dirname(targetpath)
if upperdirs and not os.path.exists(upperdirs):
os.makedirs(upperdirs)
if member.filename[-1] == '/':
if not os.path.isdir(targetpath):