MCPcopy Index your code
hub / github.com/python/cpython / test_malformed_paths

Method test_malformed_paths

Lib/test/test_zipfile/_path/test_path.py:608–624  ·  view source on GitHub ↗

Path should handle malformed paths gracefully. Paths with leading slashes are not visible. Paths with dots are treated like regular files.

(self)

Source from the content-addressed store, hash-verified

606 alpharep.getinfo('does-not-exist')
607
608 def test_malformed_paths(self):
609 """
610 Path should handle malformed paths gracefully.
611
612 Paths with leading slashes are not visible.
613
614 Paths with dots are treated like regular files.
615 """
616 data = io.BytesIO()
617 zf = zipfile.ZipFile(data, "w")
618 zf.writestr("/one-slash.txt", b"content")
619 zf.writestr("//two-slash.txt", b"content")
620 zf.writestr("../parent.txt", b"content")
621 zf.filename = ''
622 root = zipfile.Path(zf)
623 assert list(map(str, root.iterdir())) == ['../']
624 assert root.joinpath('..').joinpath('parent.txt').read_bytes() == b'content'
625
626 def test_unsupported_names(self):
627 """

Callers

nothing calls this directly

Calls 6

writestrMethod · 0.95
iterdirMethod · 0.95
joinpathMethod · 0.95
listClass · 0.85
read_bytesMethod · 0.45
joinpathMethod · 0.45

Tested by

no test coverage detected