Skip to content

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

Open
cig13zs wants to merge 1 commit into
cpburnz:masterfrom
cig13zs:fix-trailing-globstar-backslash
Open

cig13zs wants to merge 1 commit into
cpburnz:masterfrom
cig13zs:fix-trailing-globstar-backslash

Conversation

@cig13zs

@cig13zs cig13zs commented Nov 26, 2026

Copy link
Copy Markdown

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).

This branch has not been deployed

No deployments
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.

1 participant