Skip to content

globset: add POSIX character class support in bracket expressions#3281

Open
KevinKickass wants to merge 2 commits intoBurntSushi:masterfrom
KevinKickass:feat/posix-character-classes
Open

globset: add POSIX character class support in bracket expressions#3281
KevinKickass wants to merge 2 commits intoBurntSushi:masterfrom
KevinKickass:feat/posix-character-classes

Conversation

@KevinKickass
Copy link
Copy Markdown

Closes #2962

This adds support for POSIX character classes ([[:space:]], [[:digit:]], etc.) inside bracket expressions in globset, as defined in POSIX XBD §9.3.5. This is consistent with how git's wildmatch handles POSIX classes in glob patterns (see also git's t3070 tests).

Approach: POSIX classes are expanded into ASCII char ranges at parse time, so Token::Class remains unchanged. A try_parse_posix_class() method saves/restores parser state on failure, letting invalid class names (e.g. [[:bogus:]]) fall through gracefully — the [ is treated as a literal.

All 12 standard POSIX classes are supported (alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit), ASCII-only to avoid locale-dependent behavior.

POSIX classes compose naturally with existing syntax:

  • Mixed with ranges: [[:digit:]a-f]
  • Multiple classes: [[:digit:][:alpha:]]
  • Negated: [^[:digit:]]

44 new tests covering parsing, matching, negation, mixed ranges, and real-world filename patterns. Full test suite passes (globset + ripgrep).

Prior art: PR #3210 attempted this but was closed due to CI failures from adding a new Token variant. This PR avoids that entirely by expanding at parse time.

Expand POSIX classes (e.g. [[:space:]], [[:digit:]]) into ASCII char
ranges at parse time. Token::Class remains unchanged, so this has no
impact on fuzz/arbitrary targets.

All 12 standard classes supported: alnum, alpha, blank, cntrl, digit,
graph, lower, print, punct, space, upper, xdigit.

ASCII-only definitions, no locale-dependent behavior.

Fixes BurntSushi#2962
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.

Missing support for [[:space:]] match group in the ignore crate

1 participant