fix: negate [!...] bracket expressions like [^...]#180
Open
spokodev wants to merge 1 commit into
Open
Conversation
A leading `!` inside a bracket expression is a negation operator,
equivalent to `^` (POSIX 2.13.1, Bash). picomatch honored `[^...]` but
left `[!...]` un-negated, treating `!` as a literal class member:
picomatch.isMatch('a', '[!a]') // true, expected false
picomatch.isMatch('b', '[!a]') // false, expected true
The `!`→`^` conversion was gated behind `opts.posix`, but basic
single-`!` negation is core glob syntax and `[^...]` already works
without the flag. Removing the gate makes `[!a]` compile to the same
negated class as `[^a]`. A `!` that is not the first bracket character
stays literal (`[a!]`).
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.
A leading
!inside a bracket expression is a negation operator, equivalent to^(POSIX 2.13.1, Bash 4.3). picomatch honors[^...]but leaves[!...]un-negated, treating!as a literal class member:Bash and
minimatchboth negate here. The!→^conversion inlib/parse.jswas gated behindopts.posix === true, but single-!negation is core glob syntax (theposixoption is documented for named classes like[:alpha:]), and[^...]already works without the flag.Removing the gate makes
[!a]compile to the same negated class as[^a]. Theprev.value === "["guard keeps a non-leading!literal ([a!]is unchanged). Full suite stays at 1975 passing with no regressions; added bracket-negation tests.