From 6957930d38b3b785bf040b28277e87ba9e8ebfbe Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Mon, 2 May 2022 15:44:06 -0400 Subject: [PATCH] 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 e1833dd1772d56e..83d0149e9a5165f 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -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 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 000000000000000..eda073611ef7f04 --- /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.