cpython: ebef003a2acd (original) (raw)
--- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -434,8 +434,6 @@ class TestsWithSourceFile(unittest.TestC ('/foo/bar', 'foo/bar'), ('/foo/../bar', 'foo/bar'), ('/foo/../../bar', 'foo/bar'),
('//foo/bar', 'foo/bar'),[](#l1.7)
('../../foo../../ba..r', 'foo../ba..r'),[](#l1.8) ][](#l1.9) if os.path.sep == '\\':[](#l1.10) hacknames.extend([[](#l1.11)
@@ -447,16 +445,22 @@ class TestsWithSourceFile(unittest.TestC (r'C:/foo/bar', 'foo/bar'), (r'C://foo/bar', 'foo/bar'), (r'C:\foo\bar', 'foo/bar'),
(r'//conky/mountpoint/foo/bar', 'foo/bar'),[](#l1.16)
(r'\\conky\mountpoint\foo\bar', 'foo/bar'),[](#l1.17)
(r'//conky/mountpoint/foo/bar', 'conky/mountpoint/foo/bar'),[](#l1.18)
(r'\\conky\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'),[](#l1.19) (r'///conky/mountpoint/foo/bar', 'conky/mountpoint/foo/bar'),[](#l1.20) (r'\\\conky\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'),[](#l1.21) (r'//conky//mountpoint/foo/bar', 'conky/mountpoint/foo/bar'),[](#l1.22) (r'\\conky\\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'),[](#l1.23)
(r'//?/C:/foo/bar', 'foo/bar'),[](#l1.24)
(r'\\?\C:\foo\bar', 'foo/bar'),[](#l1.25)
(r'//?/C:/foo/bar', '_/C_/foo/bar'),[](#l1.26)
(r'\\?\C:\foo\bar', '_/C_/foo/bar'),[](#l1.27) (r'C:/../C:/foo/bar', 'C_/foo/bar'),[](#l1.28) (r'a:b\c<d>e|f"g?h*i', 'b/c_d_e_f_g_h_i'),[](#l1.29)
('../../foo../../ba..r', 'foo/ba..r'),[](#l1.30)
])[](#l1.31)
else: # Unix[](#l1.32)
hacknames.extend([[](#l1.33)
('//foo/bar', 'foo/bar'),[](#l1.34)
('../../foo../../ba..r', 'foo../ba..r'),[](#l1.35) ])[](#l1.36)
for arcname, fixedname in hacknames: @@ -469,7 +473,8 @@ class TestsWithSourceFile(unittest.TestC with zipfile.ZipFile(TESTFN2, 'r') as zipfp: writtenfile = zipfp.extract(arcname, targetpath)
self.assertEqual(writtenfile, correctfile)[](#l1.43)
self.assertEqual(writtenfile, correctfile,[](#l1.44)
msg="extract %r" % arcname)[](#l1.45) self.check_file(correctfile, content)[](#l1.46) shutil.rmtree('target')[](#l1.47)
@@ -482,7 +487,8 @@ class TestsWithSourceFile(unittest.TestC with zipfile.ZipFile(TESTFN2, 'r') as zipfp: writtenfile = zipfp.extract(arcname)
self.assertEqual(writtenfile, correctfile)[](#l1.53)
self.assertEqual(writtenfile, correctfile,[](#l1.54)
msg="extract %r" % arcname)[](#l1.55) self.check_file(correctfile, content)[](#l1.56) shutil.rmtree(fixedname.split('/')[0])[](#l1.57)
--- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1050,11 +1050,14 @@ class ZipFile(object): 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[](#l2.7) if os.path.sep == '\\':[](#l2.8)
# filter illegal characters on Windows[](#l2.9) illegal = ':<>|"?*'[](#l2.10) table = string.maketrans(illegal, '_' * len(illegal))[](#l2.11) arcname = arcname.translate(table)[](#l2.12)
# remove trailing dots[](#l2.13)
arcname = (x.rstrip('.') for x in arcname.split(os.path.sep))[](#l2.14)
arcname = os.path.sep.join(x for x in arcname if x)[](#l2.15)
targetpath = os.path.join(targetpath, arcname) targetpath = os.path.normpath(targetpath)