diff options
author | Brett Cannon <brett@python.org> | 2013-02-01 16:36:49 -0500 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-02-01 16:36:49 -0500 |
commit | 0bc4329cda62d3c84fbae8560ee33577b1bc903c (patch) | |
tree | c1c69fd9841d11a974c8b4c97a736339ce1d688f /Lib/zipfile.py | |
parent | 85ae3566d117df8f0ade3aa14a6ddda09711a663 (diff) | |
parent | 84d0bf94b036c5eb62b1fe31d33133a5ee05516d (diff) | |
download | cpython-git-0bc4329cda62d3c84fbae8560ee33577b1bc903c.tar.gz |
merge
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 509cba9789..2ad4f88f28 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1229,17 +1229,22 @@ class ZipFile: """ # build the destination pathname, replacing # forward slashes to platform specific separators. - # Strip trailing path separator, unless it represents the root. - if (targetpath[-1:] in (os.path.sep, os.path.altsep) - 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) - + arcname = member.filename.replace('/', os.path.sep) + + if os.path.altsep: + arcname = arcname.replace(os.path.altsep, os.path.sep) + # interpret absolute pathname as relative, remove drive letter or + # UNC path, redundant separators, "." and ".." components. + arcname = os.path.splitdrive(arcname)[1] + arcname = os.path.sep.join(x for x in arcname.split(os.path.sep) + if x not in ('', os.path.curdir, os.path.pardir)) + # filter illegal characters on Windows + if os.path.sep == '\\': + illegal = ':<>|"?*' + table = str.maketrans(illegal, '_' * len(illegal)) + arcname = arcname.translate(table) + + targetpath = os.path.join(targetpath, arcname) targetpath = os.path.normpath(targetpath) # Create all upper directories if necessary. |