[Python-checkins] gh-94018: Remove trailing spaces in _sanitize_windows_name (GH-94040)
ambv
webhook-mailer at python.org
Tue Jun 28 06:09:41 EDT 2022
https://github.com/python/cpython/commit/176fd5571f299e6b3e6168e430a0d2f8d425d920
commit: 176fd5571f299e6b3e6168e430a0d2f8d425d920
branch: main
author: Robin Plumey <44498456+Rygone at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2022-06-28T12:09:22+02:00
summary:
gh-94018: Remove trailing spaces in _sanitize_windows_name (GH-94040)
Closes #94018.
Co-authored-by: Sam Ezeh <sam.z.ezeh at gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja at users.noreply.github.com>
Co-authored-by: Zachary Ware <zachary.ware at gmail.com>
files:
A Misc/NEWS.d/next/Windows/2022-06-20-22-32-14.gh-issue-94018.bycC3A.rst
M Lib/test/test_zipfile.py
M Lib/zipfile.py
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index f4c11d88c8a09..fa0ca5aa7428a 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -1440,6 +1440,8 @@ def test_sanitize_windows_name(self):
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 = [
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index fc6ca65e5ed1e..e3b7a61a6399b 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1685,8 +1685,8 @@ def _sanitize_windows_name(cls, arcname, pathsep):
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
index 0000000000000..a2e558b3b4b3a
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2022-06-20-22-32-14.gh-issue-94018.bycC3A.rst
@@ -0,0 +1 @@
+:mod:`zipfile` will now remove trailing spaces from path components when extracting files on Windows.
More information about the Python-checkins
mailing list