]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94018: Remove trailing spaces in _sanitize_windows_name (GH-94040)
authorRobin Plumey <44498456+Rygone@users.noreply.github.com>
Tue, 28 Jun 2022 10:09:22 +0000 (12:09 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Jun 2022 10:09:22 +0000 (12:09 +0200)
Closes #94018.

Co-authored-by: Sam Ezeh <sam.z.ezeh@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Zachary Ware <zachary.ware@gmail.com>
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS.d/next/Windows/2022-06-20-22-32-14.gh-issue-94018.bycC3A.rst [new file with mode: 0644]

index f4c11d88c8a09fa2b9e9e823c825b7a2f1436d7a..fa0ca5aa7428ace787e11f99741f85e8209a5db6 100644 (file)
@@ -1440,6 +1440,8 @@ class ExtractTests(unittest.TestCase):
         self.assertEqual(san(r',,?,C:,foo,bar/z', ','), r'_,C_,foo,bar/z')
         self.assertEqual(san(r'a\b,c<d>e|f"g?h*i', ','), r'a\b,c_d_e_f_g_h_i')
         self.assertEqual(san('../../foo../../ba..r', '/'), r'foo/ba..r')
+        self.assertEqual(san('  /  /foo  /  /ba  r', '/'), r'foo/ba  r')
+        self.assertEqual(san(' . /. /foo ./ . /. ./ba .r', '/'), r'foo/ba .r')
 
     def test_extract_hackers_arcnames_common_cases(self):
         common_hacknames = [
index fc6ca65e5ed1e9e95745fb5fd7e2c4bd3683f516..e3b7a61a6399be129c22c89e6242560a025f8ad5 100644 (file)
@@ -1685,8 +1685,8 @@ class ZipFile:
             table = str.maketrans(illegal, '_' * len(illegal))
             cls._windows_illegal_name_trans_table = table
         arcname = arcname.translate(table)
-        # remove trailing dots
-        arcname = (x.rstrip('.') for x in arcname.split(pathsep))
+        # remove trailing dots and spaces
+        arcname = (x.rstrip(' .') for x in arcname.split(pathsep))
         # rejoin, removing empty parts.
         arcname = pathsep.join(x for x in arcname if x)
         return arcname
diff --git a/Misc/NEWS.d/next/Windows/2022-06-20-22-32-14.gh-issue-94018.bycC3A.rst b/Misc/NEWS.d/next/Windows/2022-06-20-22-32-14.gh-issue-94018.bycC3A.rst
new file mode 100644 (file)
index 0000000..a2e558b
--- /dev/null
@@ -0,0 +1 @@
+:mod:`zipfile` will now remove trailing spaces from path components when extracting files on Windows.