diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-07 01:45:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-07 01:45:37 (GMT) |
commit | db6f297d448ce46e58a5b90239a4779553333198 (patch) | |
tree | 5815dc2c1e9fb9c7ca5128d0228d11d585044f44 /Lib/test | |
parent | 4d5328cbebc441ed2539ad3b2ea30a01eb059ef7 (diff) | |
download | cpython-db6f297d448ce46e58a5b90239a4779553333198.zip cpython-db6f297d448ce46e58a5b90239a4779553333198.tar.gz cpython-db6f297d448ce46e58a5b90239a4779553333198.tar.bz2 |
[3.12] gh-112795: Allow `/` folder in a zipfile (GH-112932) (#113789)
gh-112795: Allow `/` folder in a zipfile (GH-112932)
Allow extraction (no-op) of a "/" folder in a zipfile, they are commonly added by some archive creation tools.
(cherry picked from commit 541c5dbb81c784afd587406be2cc82645979a107)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_zipfile/_path/test_path.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile/_path/test_path.py b/Lib/test/test_zipfile/_path/test_path.py index c66cb3c..171ab6f 100644 --- a/Lib/test/test_zipfile/_path/test_path.py +++ b/Lib/test/test_zipfile/_path/test_path.py @@ -577,3 +577,15 @@ class TestPath(unittest.TestCase): zipfile.Path(alpharep) with self.assertRaises(KeyError): alpharep.getinfo('does-not-exist') + + def test_root_folder_in_zipfile(self): + """ + gh-112795: Some tools or self constructed codes will add '/' folder to + the zip file, this is a strange behavior, but we should support it. + """ + in_memory_file = io.BytesIO() + zf = zipfile.ZipFile(in_memory_file, "w") + zf.mkdir('/') + zf.writestr('./a.txt', 'aaa') + tmpdir = pathlib.Path(self.fixtures.enter_context(temp_dir())) + zf.extractall(tmpdir) |