From f89b93f0370dd85d23d243e25dfc1f99f4d8de48 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 26 Aug 2024 10:32:26 -0400 Subject: [PATCH] Address infinite loop when zipfile begins with more than one leading slash. Alternate and more surgical fix for jaraco/zipp#119. Ref python/cpython#123270 --- pyproject.toml | 1 - tests/test_path.py | 1 - zipp/__init__.py | 9 +++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 874996b..db9823d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,6 @@ test = [ "pytest-ignore-flaky", "jaraco.test", "importlib_resources; python_version < '3.9'", - "pytest-timeout", ] doc = [ diff --git a/tests/test_path.py b/tests/test_path.py index 4571c00..4884587 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -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. diff --git a/zipp/__init__.py b/zipp/__init__.py index 051bfc9..0b7b443 100644 --- a/zipp/__init__.py +++ b/zipp/__init__.py @@ -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'] @@ -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)