Skip to content

Commit

Permalink
Convert os.altsep to '/' in filenames when creating ZipInfo objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pR0Ps committed Feb 20, 2023
1 parent c00faf7 commit 6957930
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/zipfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
# ZIP format specification.
if os.sep != "/" and os.sep in filename:
filename = filename.replace(os.sep, "/")
if os.altsep and os.altsep != "/" and os.altsep in filename:
filename = filename.replace(os.altsep, "/")

self.filename = filename # Normalized file name
self.date_time = date_time # year, month, day, hour, min, sec
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When creating zip files using the ``zipfile`` module, ``os.altsep`` will always
be treated as a path separator. Patch by Carey Metcalfe.

0 comments on commit 6957930

Please sign in to comment.