Skip to content

Commit 60fbc56

Browse files
committed
fix: Directory matching behavior, ignore empty patterns
1 parent ea1485c commit 60fbc56

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/bids_validator/bidsignore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def compile_pat(pattern: str) -> Union[re.Pattern, None]:
4949
]
5050

5151
prefix = '^' if relative_match else '^(?:.*/|)'
52-
postfix = r'/\Z' if directory_match else r'/?\Z'
52+
postfix = r'/' if directory_match else r'(/|\Z)'
5353

5454
# "**/" matches zero or more directories, so wrap in an optional segment
5555
out_pattern = '/'.join(parts).replace('.*/', '(?:.*/)?')
@@ -84,7 +84,7 @@ def from_file(cls, pathlike: os.PathLike):
8484

8585
def match(self, relpath: str) -> bool:
8686
"""Match a relative path against a collection of ignore patterns."""
87-
if any(compile_pat(pattern).match(relpath) for pattern in self.patterns):
87+
if any(compile_pat(pattern).match(relpath) for pattern in self.patterns if pattern):
8888
self.history.append(relpath)
8989
return True
9090
return False

tests/test_bidsignore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
('frotz/', ['frotz/', 'doc/frotz/', 'a/doc/frotz/'], []),
2424
# * matches everything because everything has a basename
2525
('*', ['foo', 'foo/', 'foo/bar', 'foo/bar/'], []),
26-
# *o matches things with basename ending in o
27-
('*o', ['foo', 'foo/', 'bar/foo', 'bar/foo/'], ['foo/bar', 'foo/bar/']),
26+
# *o matches things with basename ending in o, including parent directories
27+
('*o', ['foo', 'foo/', 'bar/foo', 'bar/foo/', 'foo/bar'], ['bar', 'bar/baz', 'bar/bar/']),
2828
# Leading **/ matches in all directories
2929
(
3030
'**/foo',
31-
['foo', 'foo/', 'bar/foo', 'bar/foo/'],
32-
['foo/bar', 'foo/bar/', 'baz/foobar', 'baz/barfoo'],
31+
['foo', 'foo/', 'bar/foo', 'bar/foo/', 'foo/bar'],
32+
['foobar/baz', 'foobar/baz/', 'baz/foobar', 'baz/barfoo'],
3333
),
3434
('**/foo/bar', ['foo/bar', 'foo/bar/', 'a/foo/bar'], ['foo/', 'bar/foo', 'bar']),
3535
# Trailing /** matches everything inside a root-relative directory

0 commit comments

Comments
 (0)