Skip to content

Treat a trailing **\ as an invalid gitignore pattern - #188

Merged
cpburnz merged 1 commit into
cpburnz:masterfrom
cig13zs:fix-trailing-globstar-backslash
Dec 3, 2026
Merged

cpburnz merged 1 commit into
cpburnz:masterfrom
cig13zs:fix-trailing-globstar-backslash

Conversation

@cig13zs

@cig13zs cig13zs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

GitIgnoreSpecPattern matches everything for a pattern that ends in **\:

>>> GitIgnoreSpecPattern('**\\').regex
re.compile('^(?s:.+/)?(?s:.+)(?:(?P<ps_d>/)|\\Z)')
>>> GitIgnoreSpec.from_lines(['a/**\\']).match_file('a/b')
True

Git treats these as a trailing backslash and ignores nothing (checked with git ls-files -o -i on 2.47 for **\, ***\, a/**\ and a/***\). GitIgnoreBasicPattern already returns a null pattern here, and **\ is in its ESCAPED_SLASH_FAIL_CASES.

The **\ special case in __translate_segments() is meant for **\/..., but it also caught the last segment, so the trailing backslash check never ran. It now only applies before the last segment. **\/b and a/**\/b are unchanged.

Added **\ and a/**\ to the spec fail cases. python -m unittest passes (322 tests, re2 and hyperscan installed).

@cpburnz
cpburnz merged commit 4b6b12b into cpburnz:master Dec 3, 2026
6 of 7 checks passed
@cpburnz

cpburnz commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Thanks for finding and fixing this bug!

cpburnz added a commit that referenced this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants