Skip to content

Commit

Permalink
GH-92184: Convert os.altsep to '/' in filenames when creating ZipInfo…
Browse files Browse the repository at this point in the history
… 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 "/").
  • Loading branch information
pR0Ps committed May 11, 2023
1 parent fcd5fb4 commit 4abfe6a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/zipfile/__init__.py
Expand Up @@ -352,6 +352,8 @@ def _sanitize_filename(filename):
# 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, "/")
return filename


Expand Down
@@ -0,0 +1,3 @@
When creating zip files using :mod:`zipfile`, ``os.altsep``, if not ``None``,
will always be treated as a path separator even when it is not ``/``.
Patch by Carey Metcalfe.

0 comments on commit 4abfe6a

Please sign in to comment.