]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-92184: Convert os.altsep to '/' in filenames when creating ZipInfo objects (#92185)
authorCarey Metcalfe <carey@cmetcalfe.ca>
Thu, 11 May 2023 07:25:16 +0000 (01:25 -0600)
committerGitHub <noreply@github.com>
Thu, 11 May 2023 07:25:16 +0000 (07:25 +0000)
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 "/").

Lib/zipfile/__init__.py
Misc/NEWS.d/next/Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst [new file with mode: 0644]

index 95c047991f872b1d1635c5cb0908db24accbab59..116b939e55fe7055fd465be2c11979ceb34ecde5 100644 (file)
@@ -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
 
 
diff --git a/Misc/NEWS.d/next/Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst b/Misc/NEWS.d/next/Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst
new file mode 100644 (file)
index 0000000..65dbdc9
--- /dev/null
@@ -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.