Skip to content

Commit

Permalink
Address infinite loop when zipfile begins with more than one leading …
Browse files Browse the repository at this point in the history
…slash.

Alternate and more surgical fix for #119. Ref python/cpython#123270
  • Loading branch information
jaraco committed Aug 26, 2024
1 parent cb04072 commit 9bee3b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ test = [
"pytest-ignore-flaky",
"jaraco.test",
"importlib_resources; python_version < '3.9'",
"pytest-timeout",
]

doc = [
Expand Down
1 change: 0 additions & 1 deletion tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ def test_getinfo_missing(self, alpharep):
alpharep.getinfo('does-not-exist')

@pytest.mark.xfail(reason="python/cpython#123270")
@pytest.mark.timeout(1)
def test_malformed_paths(self):
"""
Path should handle malformed paths.
Expand Down
9 changes: 7 additions & 2 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _parents(path):
def _ancestry(path):
"""
Given a path with elements separated by
posixpath.sep, generate all elements of that path
posixpath.sep, generate all elements of that path.
>>> list(_ancestry('b/d'))
['b/d', 'b']
Expand All @@ -58,9 +58,14 @@ def _ancestry(path):
['b']
>>> list(_ancestry(''))
[]
Multiple separators are treated like a single.
>>> list(_ancestry('//b//d///f//'))
['//b//d///f', '//b//d', '//b']
"""
path = path.rstrip(posixpath.sep)
while path and path != posixpath.sep:
while path and not path.endswith(posixpath.sep):
yield path
path, tail = posixpath.split(path)

Expand Down

0 comments on commit 9bee3b9

Please sign in to comment.