Skip to content

Escape a leading ':', '.' or '=' in gitignore bracket expressions - #194

Merged
cpburnz merged 1 commit into
cpburnz:masterfrom
cig13zs:fix-hyperscan-bracket-colon
Dec 4, 2026
Merged

cpburnz merged 1 commit into
cpburnz:masterfrom
cig13zs:fix-hyperscan-bracket-colon

Conversation

@cig13zs

@cig13zs cig13zs commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

[:alpha:] (without the outer brackets) is a valid gitignore line. Git reads it as a bracket expression of :, a, l, p, h, and that's what the simple and re2 backends do. The hyperscan backend fails to build the spec though, because the translated regex is passed through as [:alpha:]:

>>> GitIgnoreSpec.from_lines(['[:alpha:]'], backend='hyperscan')
hyperscan.error: POSIX named classes are only supported inside a class at index 10.

Same for [.a.] and [=a=] ("Unsupported POSIX collating element"). Since hyperscan is picked by 'best' when re2 isn't installed, one such line in a .gitignore breaks the whole spec.

The fix escapes a leading :, . or = in a non-negated bracket body, next to the existing ^ escape. Negated ones already start with [^/ so they're fine. Matching doesn't change (checked against git ls-files -o -i on 2.47).

Added test_posix_like_body to test_08_gitignore_bracket_slash.py; it errors on hyperscan without the fix. python -m unittest passes (332 tests, re2 and hyperscan installed).

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

cpburnz commented Dec 4, 2026

Copy link
Copy Markdown
Owner

I'd never heard of the POSIX collating element or equivalence class before. Thanks for fixing this!

cpburnz added a commit that referenced this pull request Dec 4, 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