Serhiy Storchaka added the comment:

Here are patches which possible fixes some of this failures.

----------
Added file: http://bugs.python.org/file28932/zipfile_fix_arcname_4-2.7.patch
Added file: http://bugs.python.org/file28933/zipfile_fix_arcname_4-3.x.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6972>
_______________________________________
diff -r b6b707063991 Lib/test/test_zipfile.py
--- a/Lib/test/test_zipfile.py  Sat Feb 02 13:27:02 2013 +0200
+++ b/Lib/test/test_zipfile.py  Sat Feb 02 15:07:52 2013 +0200
@@ -434,8 +434,6 @@
             ('/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 @@
                 (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 @@
 
             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 @@
 
             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])
 
diff -r b6b707063991 Lib/zipfile.py
--- a/Lib/zipfile.py    Sat Feb 02 13:27:02 2013 +0200
+++ b/Lib/zipfile.py    Sat Feb 02 15:07:52 2013 +0200
@@ -1050,11 +1050,14 @@
         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)
diff -r 25294188c4ea Lib/test/test_zipfile.py
--- a/Lib/test/test_zipfile.py  Sat Feb 02 13:28:42 2013 +0200
+++ b/Lib/test/test_zipfile.py  Sat Feb 02 15:08:04 2013 +0200
@@ -548,8 +548,6 @@
             ('/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 == '\\':  # Windows.
             hacknames.extend([
@@ -571,6 +569,12 @@
                 (r'\\?\C:\foo\bar', '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:
@@ -583,7 +587,8 @@
 
             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')
 
@@ -596,7 +601,8 @@
 
             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])
 
diff -r 25294188c4ea Lib/zipfile.py
--- a/Lib/zipfile.py    Sat Feb 02 13:28:42 2013 +0200
+++ b/Lib/zipfile.py    Sat Feb 02 15:08:04 2013 +0200
@@ -1238,11 +1238,14 @@
         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 = str.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)
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to