summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-22 18:35:12 (GMT)
committerGitHub <noreply@github.com>2024-03-22 18:35:12 (GMT)
commitf3fee231d359979133e1d58085f43277c41476d0 (patch)
treed5a28e909420cf969bbf35951b5bb2334afba5c5 /Lib/test
parent135a698d5cbb9090fa980efcbb15bcf6063ad5b7 (diff)
downloadcpython-f3fee231d359979133e1d58085f43277c41476d0.zip
cpython-f3fee231d359979133e1d58085f43277c41476d0.tar.gz
cpython-f3fee231d359979133e1d58085f43277c41476d0.tar.bz2
[3.12] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) (GH-117162)
(cherry picked from commit 567ab3bd15398c8c7b791f3e376ae3e3c0bbe079)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_zipfile/test_core.py16
-rw-r--r--Lib/test/zipdir_backslash.zipbin0 -> 192 bytes
2 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py
index ae58145..5b32f80 100644
--- a/Lib/test/test_zipfile/test_core.py
+++ b/Lib/test/test_zipfile/test_core.py
@@ -2937,6 +2937,22 @@ class TestWithDirectory(unittest.TestCase):
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 0000000..979126e
--- /dev/null
+++ b/Lib/test/zipdir_backslash.zip
Binary files differ