Skip to content

Commit de8ff78

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 56f9844 commit de8ff78

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Lib/zipfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
380380
# ZIP format specification.
381381
if os.sep != "/" and os.sep in filename:
382382
filename = filename.replace(os.sep, "/")
383+
if os.altsep and os.altsep != "/" and os.altsep in filename:
384+
filename = filename.replace(os.altsep, "/")
383385

384386
self.filename = filename # Normalized file name
385387
self.date_time = date_time # year, month, day, hour, min, sec
Lines changed: 2 additions & 0 deletions
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)