Skip to content

Commit c0fa220

Browse files
committed
Convert os.altsep to '/' in filenames when creating ZipInfo objects
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.
1 parent 3d29eda commit c0fa220

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Lib/zipfile/__init__.py

+2
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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
When creating zip files using the ``zipfile`` module, ``os.altsep`` will always
2+
be treated as a path separator. Patch by Carey Metcalfe.

0 commit comments

Comments
 (0)