Skip to content

Commit 6957930

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 c00faf7 commit 6957930

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
@@ -376,6 +376,8 @@ def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
376376
# ZIP format specification.
377377
if os.sep != "/" and os.sep in filename:
378378
filename = filename.replace(os.sep, "/")
379+
if os.altsep and os.altsep != "/" and os.altsep in filename:
380+
filename = filename.replace(os.altsep, "/")
379381

380382
self.filename = filename # Normalized file name
381383
self.date_time = date_time # year, month, day, hour, min, sec
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)