Skip to content

Commit 4abfe6a

Browse files
authored
GH-92184: Convert os.altsep to '/' in filenames when creating ZipInfo objects (#92185)
This causes the zipfile module to also consider the character defined by `os.altsep` (if there is one) to be a path separator and convert it to a forward slash, as defined by the zip specification. A logical no-op on all known platforms today as os.altsep is currently only set to a meaningful value on Windows (where it is "/").
1 parent fcd5fb4 commit 4abfe6a

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Lib/zipfile/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ def _sanitize_filename(filename):
352352
# ZIP format specification.
353353
if os.sep != "/" and os.sep in filename:
354354
filename = filename.replace(os.sep, "/")
355+
if os.altsep and os.altsep != "/" and os.altsep in filename:
356+
filename = filename.replace(os.altsep, "/")
355357
return filename
356358

357359

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When creating zip files using :mod:`zipfile`, ``os.altsep``, if not ``None``,
2+
will always be treated as a path separator even when it is not ``/``.
3+
Patch by Carey Metcalfe.

0 commit comments

Comments
 (0)