From 0d820476458624cd7086e25d4eea5ed046bb92a9 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 22 Mar 2024 21:24:27 +0200 Subject: [PATCH] [3.11] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) (GH-117162) (GH-117165) (cherry picked from commit f3fee231d359979133e1d58085f43277c41476d0) Co-authored-by: Serhiy Storchaka (cherry picked from commit 567ab3bd15398c8c7b791f3e376ae3e3c0bbe079) --- Lib/test/test_zipfile.py | 16 ++++++++++++++++ Lib/test/zipdir_backslash.zip | Bin 0 -> 192 bytes Lib/zipfile.py | 10 +++++++++- ...24-03-21-17-07-38.gh-issue-117084.w1mTpT.rst | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Lib/test/zipdir_backslash.zip create mode 100644 Misc/NEWS.d/next/Library/2024-03-21-17-07-38.gh-issue-117084.w1mTpT.rst diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index bb5dad2d17bbd4..4de6f379a47891 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -2882,6 +2882,22 @@ def test_bug_6050(self): os.mkdir(os.path.join(TESTFN2, "a")) self.test_extract_dir() + def test_extract_dir_backslash(self): + zfname = findfile("zipdir_backslash.zip") + with zipfile.ZipFile(zfname) as zipf: + zipf.extractall(TESTFN2) + if os.name == 'nt': + self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a"))) + self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b"))) + self.assertTrue(os.path.isfile(os.path.join(TESTFN2, "a", "b", "c"))) + self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "d"))) + self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "d", "e"))) + else: + self.assertTrue(os.path.isfile(os.path.join(TESTFN2, "a\\b\\c"))) + self.assertTrue(os.path.isfile(os.path.join(TESTFN2, "d\\e\\"))) + self.assertFalse(os.path.exists(os.path.join(TESTFN2, "a"))) + self.assertFalse(os.path.exists(os.path.join(TESTFN2, "d"))) + def test_write_dir(self): dirpath = os.path.join(TESTFN2, "x") os.mkdir(dirpath) diff --git a/Lib/test/zipdir_backslash.zip b/Lib/test/zipdir_backslash.zip new file mode 100644 index 0000000000000000000000000000000000000000..979126ef5e37ebd46762c76439e9b4e77431103c GIT binary patch literal 192 zcmWIWW@Zs#0D