Skip to content

Commit 176fd55

Browse files
Rygonedignissimushauntsaninjazware
authored
gh-94018: Remove trailing spaces in _sanitize_windows_name (GH-94040)
Closes #94018. Co-authored-by: Sam Ezeh <[email protected]> Co-authored-by: Shantanu <[email protected]> Co-authored-by: Zachary Ware <[email protected]>
1 parent 81ac9ac commit 176fd55

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Lib/test/test_zipfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,8 @@ def test_sanitize_windows_name(self):
14401440
self.assertEqual(san(r',,?,C:,foo,bar/z', ','), r'_,C_,foo,bar/z')
14411441
self.assertEqual(san(r'a\b,c<d>e|f"g?h*i', ','), r'a\b,c_d_e_f_g_h_i')
14421442
self.assertEqual(san('../../foo../../ba..r', '/'), r'foo/ba..r')
1443+
self.assertEqual(san(' / /foo / /ba r', '/'), r'foo/ba r')
1444+
self.assertEqual(san(' . /. /foo ./ . /. ./ba .r', '/'), r'foo/ba .r')
14431445

14441446
def test_extract_hackers_arcnames_common_cases(self):
14451447
common_hacknames = [

Lib/zipfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,8 @@ def _sanitize_windows_name(cls, arcname, pathsep):
16851685
table = str.maketrans(illegal, '_' * len(illegal))
16861686
cls._windows_illegal_name_trans_table = table
16871687
arcname = arcname.translate(table)
1688-
# remove trailing dots
1689-
arcname = (x.rstrip('.') for x in arcname.split(pathsep))
1688+
# remove trailing dots and spaces
1689+
arcname = (x.rstrip(' .') for x in arcname.split(pathsep))
16901690
# rejoin, removing empty parts.
16911691
arcname = pathsep.join(x for x in arcname if x)
16921692
return arcname
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:mod:`zipfile` will now remove trailing spaces from path components when extracting files on Windows.

0 commit comments

Comments
 (0)