]> granicus.if.org Git - python/commitdiff
Fix the test and remove trailing dots on Windows for issue #6972.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 2 Feb 2013 15:46:33 +0000 (17:46 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 2 Feb 2013 15:46:33 +0000 (17:46 +0200)
Lib/test/test_zipfile.py
Lib/zipfile.py

index 58d3c4883a26916aa64f79a44fe787b20847def2..f535e56e9b9690675c6cb0834bea5e0d8f4ee7cd 100644 (file)
@@ -434,8 +434,6 @@ class TestsWithSourceFile(unittest.TestCase):
             ('/foo/bar', 'foo/bar'),
             ('/foo/../bar', 'foo/bar'),
             ('/foo/../../bar', 'foo/bar'),
-            ('//foo/bar', 'foo/bar'),
-            ('../../foo../../ba..r', 'foo../ba..r'),
         ]
         if os.path.sep == '\\':
             hacknames.extend([
@@ -447,16 +445,22 @@ class TestsWithSourceFile(unittest.TestCase):
                 (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'),
-                (r'\\conky\mountpoint\foo\bar', 'foo/bar'),
+                (r'//conky/mountpoint/foo/bar', 'conky/mountpoint/foo/bar'),
+                (r'\\conky\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'),
                 (r'///conky/mountpoint/foo/bar', 'conky/mountpoint/foo/bar'),
                 (r'\\\conky\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'),
                 (r'//conky//mountpoint/foo/bar', 'conky/mountpoint/foo/bar'),
                 (r'\\conky\\mountpoint\foo\bar', 'conky/mountpoint/foo/bar'),
-                (r'//?/C:/foo/bar', 'foo/bar'),
-                (r'\\?\C:\foo\bar', 'foo/bar'),
+                (r'//?/C:/foo/bar', '_/C_/foo/bar'),
+                (r'\\?\C:\foo\bar', '_/C_/foo/bar'),
                 (r'C:/../C:/foo/bar', 'C_/foo/bar'),
                 (r'a:b\c<d>e|f"g?h*i', 'b/c_d_e_f_g_h_i'),
+                ('../../foo../../ba..r', 'foo/ba..r'),
+            ])
+        else:  # Unix
+            hacknames.extend([
+                ('//foo/bar', 'foo/bar'),
+                ('../../foo../../ba..r', 'foo../ba..r'),
             ])
 
         for arcname, fixedname in hacknames:
@@ -469,7 +473,8 @@ class TestsWithSourceFile(unittest.TestCase):
 
             with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
                 writtenfile = zipfp.extract(arcname, targetpath)
-                self.assertEqual(writtenfile, correctfile)
+                self.assertEqual(writtenfile, correctfile,
+                                 msg="extract %r" % arcname)
             self.check_file(correctfile, content)
             shutil.rmtree('target')
 
@@ -482,7 +487,8 @@ class TestsWithSourceFile(unittest.TestCase):
 
             with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
                 writtenfile = zipfp.extract(arcname)
-                self.assertEqual(writtenfile, correctfile)
+                self.assertEqual(writtenfile, correctfile,
+                                 msg="extract %r" % arcname)
             self.check_file(correctfile, content)
             shutil.rmtree(fixedname.split('/')[0])
 
index 9af2986bf9a4e8076604ecb79effd89b748ae4d6..9d1a98479db6e2ffb2d6afca1b42eb3b74484bdb 100644 (file)
@@ -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
         if os.path.sep == '\\':
+            # filter illegal characters on Windows
             illegal = ':<>|"?*'
             table = string.maketrans(illegal, '_' * len(illegal))
             arcname = arcname.translate(table)
+            # remove trailing dots
+            arcname = (x.rstrip('.') for x in arcname.split(os.path.sep))
+            arcname = os.path.sep.join(x for x in arcname if x)
 
         targetpath = os.path.join(targetpath, arcname)
         targetpath = os.path.normpath(targetpath)