Skip to content

fix: avoid bracket class literal shortcut#176

Open
pupuking723 wants to merge 1 commit into
micromatch:masterfrom
pupuking723:fix/bracket-exact-match-shortcut
Open

fix: avoid bracket class literal shortcut#176
pupuking723 wants to merge 1 commit into
micromatch:masterfrom
pupuking723:fix/bracket-exact-match-shortcut

Conversation

@pupuking723

Copy link
Copy Markdown

Fixes #71.

picomatch.test() currently short-circuits to a successful match when the input string is exactly equal to the glob pattern. That works for literal patterns, but it bypasses regex matching for bracket character classes.

For example, [1-5] should match 1 through 5, but it should not match the literal string [1-5] unless the brackets are escaped or literalBrackets: true is used.

This change keeps the exact-match shortcut for literal patterns and explicit literal bracket matching, but disables that shortcut when the compiled state contains bracket tokens. In that case the generated regex decides the result.

Verification:

  • Added regression coverage for [1-5] vs [1-5]
  • Confirmed the new test failed before the fix
  • npm run mocha -- test/brackets.js test/regex-features.js test/special-characters.js test/bash.js
  • npm test
  • git diff --check

Signed-off-by: 王胜 <2318857637@qq.com>
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.

Incorrectly matches [1-5] against [1-5]

1 participant