fix: translate POSIX bracket negation by default - #196
Merged
mrmlnc merged 2 commits intoAug 24, 2026
Conversation
[!abc] compiled to a class containing a literal bang, so it matched exactly the characters it should exclude and rejected everything else. bash and minimatch both treat [!...] as [^...]. The translation existed but was gated behind opts.posix, which controls [[:alpha:]] classes, not basic negation. Fixes micromatch#187
This was referenced Aug 24, 2026
Keep incomplete `[!]` expressions and `literalBrackets` behavior unchanged while translating valid leading `!` expressions. Add behavior-focused coverage for ranges, embedded patterns, `posix: false`, disabled brackets, and literal bangs.
mrmlnc
force-pushed
the
fix/bracket-negation-default
branch
from
August 24, 2026 22:34
1d96dab to
73de57b
Compare
Contributor
|
This is the correct change: both Bash and Minimatch treat a leading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #187.
[!abc]compiled to a character class containing a literal!, so it matched exactly the characters it is supposed to exclude and rejected everything else:bash and minimatch both treat
[!...]as[^...]. The translation already existed in the tokenizer but was gated behindopts.posix === true, which controls[[:alpha:]]class support; basic bracket negation is POSIX sh glob, not a posix-class feature. This removes the gate, so[!abc]now produces byte-for-byte the same regex as[^abc]and as[!abc]underposix: true.Behavior notes, all locked by tests:
[!...]inherits the[^...]slash rule (a negated class never matches/).!not in first position stays literal:[a!]matchesaand!.\!in first position stays literal:[\!a]matches!anda.[!]now behaves identically to[^](both escape the lone]).Compatibility: this changes match results for any pattern relying on the inverted behavior. No test in the suite asserted the old behavior (1982 passing after the change, 8 in the new negation block), and the old output contradicts every reference implementation, but flagging it clearly in case you want it to ride a major.