Treat a leading "!" in a bracket expression as negation by default - #188
Open
MildlyMeticulous wants to merge 1 commit into
Open
Treat a leading "!" in a bracket expression as negation by default#188MildlyMeticulous wants to merge 1 commit into
MildlyMeticulous wants to merge 1 commit into
Conversation
The conversion of "[!" to "[^" was gated on options.posix, so with the default options "[!abc]" emitted "!" as an ordinary class member and the expression matched exactly the characters it should exclude. "[!...]" is Bash pattern negation rather than a POSIX bracket expression, and "[[:alpha:]]" already works without the option, so the flag was not gating what its name suggests. "[^...]" negation was already unconditional, so the two negation forms disagreed with each other by default. Removing the gate leaves all 1977 existing tests passing and takes agreement with minimatch on a 462-case bracket matrix from 376 to 441.
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.
The
[!to[^conversion inlib/parse.jswas gated onoptions.posix, so by default!was emitted as an ordinary class member and[!abc]matched exactly the characters it is meant to exclude:Three reasons the gate looks wrong rather than deliberate:
[!...]is Bash pattern negation, not a POSIX bracket expression like[[:alpha:]][[:alpha:]]already works withposixoff, so the flag was not gating the feature it is named for[^...]negation was already unconditional, so the two negation forms disagreed with each other by defaultmakeRe('[!abc]')now produces^(?:[^abc/]\/?)$, the same shape as[^abc].Compatibility
This changes default behaviour, so I measured it rather than assuming.
Existing suite: 1977 passing before, 1977 passing after, with no test edited. Nothing pinned the old behaviour; every existing
[!test is inposix-classes.jsand already runs withposix: true.Against minimatch, over a 462-case matrix of 21 bracket patterns by 22 inputs:
65 disagreements fixed, none introduced. The 21 that remain are pre-existing picomatch behaviours unrelated to this change: leading-dot handling and
/inside classes. Both also apply to[^...], which this does not touch, and they are unchanged by the patch.Tests
Six cases added to
test/brackets.js: plain negation, ranges, parity with[^...], negation inside a larger pattern,!as a literal when not leading ([a!]), and a negated literal!([!!]). Revertinglib/parse.jsand keeping the tests fails five of them.