From c0fa220c936cff6e49ca767cb702d9169560d317 Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Mon, 2 May 2022 15:44:06 -0400 Subject: [PATCH 1/2] 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. --- Lib/zipfile/__init__.py | 2 ++ .../next/Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 95c047991f872b..116b939e55fe70 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -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 index 00000000000000..eda073611ef7f0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst @@ -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. From 43da8284cf046b0f7a7b7caa4e1369f966646f3a Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Wed, 10 May 2023 23:54:56 -0700 Subject: [PATCH 2/2] reword & ReSTify the news entry. --- .../Library/2022-05-02-16-21-05.gh-issue-92184.hneGVW.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 index eda073611ef7f0..65dbdc9f60371e 100644 --- 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 @@ -1,2 +1,3 @@ -When creating zip files using the ``zipfile`` module, ``os.altsep`` will always -be treated as a path separator. Patch by Carey Metcalfe. +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.