mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-122905: Sanitize names in zipfile.Path. (#122906)
Ported from zipp 3.19.1; ref jaraco/zipp#119.
This commit is contained in:
parent
4534068f22
commit
9cd0326310
3 changed files with 81 additions and 1 deletions
|
@ -577,3 +577,20 @@ class TestPath(unittest.TestCase):
|
|||
zipfile.Path(alpharep)
|
||||
with self.assertRaises(KeyError):
|
||||
alpharep.getinfo('does-not-exist')
|
||||
|
||||
def test_malformed_paths(self):
|
||||
"""
|
||||
Path should handle malformed paths.
|
||||
"""
|
||||
data = io.BytesIO()
|
||||
zf = zipfile.ZipFile(data, "w")
|
||||
zf.writestr("/one-slash.txt", b"content")
|
||||
zf.writestr("//two-slash.txt", b"content")
|
||||
zf.writestr("../parent.txt", b"content")
|
||||
zf.filename = ''
|
||||
root = zipfile.Path(zf)
|
||||
assert list(map(str, root.iterdir())) == [
|
||||
'one-slash.txt',
|
||||
'two-slash.txt',
|
||||
'parent.txt',
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue