Skip to content

Commit 3406cc9

Browse files
committed
matchglob: Don't crash if the pattern is exhausted before the filename
1 parent 17a3104 commit 3406cc9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

domdf_python_tools/paths.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@ def matchglob(filename: PathLike, pattern: str, matchcase: bool = True) -> bool:
995995
while True:
996996
if not pattern_parts and not filename_parts:
997997
return True
998+
elif not pattern_parts and filename_parts:
999+
# Pattern exhausted but still filename elements
1000+
return False
9981001

9991002
pattern_part = pattern_parts.popleft()
10001003

tests/test_paths.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,14 @@ def test_iterchildren_no_exclusions(tmp_pathplus: PathPlus):
825825
("foo/**/**", "foo/bar.py", True),
826826
("foo/**/**", "foo/baz/bar.py", True),
827827
("foo/**/**", "foo/baz/baz/bar.py", True),
828+
("**/.tox", "foo/bar/.tox", True),
829+
("**/.tox", "foo/bar/.tox/build", False),
830+
("**/.tox/*", "foo/bar/.tox/build", True),
831+
("**/.tox/**", "foo/bar/.tox/build", True),
832+
("**/.tox/**", "foo/bar/.tox/build/baz", True),
828833
]
829834
)
830-
def test_globpath(pattern: str, filename: str, match: bool):
835+
def test_matchglob(pattern: str, filename: str, match: bool):
831836
assert matchglob(filename, pattern) is match
832837

833838

0 commit comments

Comments
 (0)