fix: treat ** adjacent to a literal as a single star (#99)#181
Open
fdma wants to merge 1 commit into
Open
Conversation
In the fast-path regex builder, `**.ext` patterns (e.g. `**.js`, `**.thing.js`) were reduced to a bare `**` and expanded to a globstar, so they incorrectly matched across path separators — `**.thing.js` matched `somepath/test.thing.js`. Per Bash semantics, `**` is only a globstar when it is the sole content of a path segment; adjacent to other characters it behaves as a single star. Bail out of the fast path for this shape and let the full parser produce the correct single-star regex (as it already did for patterns the fast path skipped, e.g. `**.dash-thing.js`). Closes micromatch#99
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.
Description
picomatch('**.thing.js')('somepath/test.thing.js')returnstruebut should returnfalse. Per Bash semantics (confirmed by @jonschlinkert in #99),**only acts as a globstar when it is the sole content of a path segment. When**is adjacent to other characters in the same segment (here.thing.js), it must behave like a single*and must not match across path separators.Closes #99.
Root cause
The bug is in the fast-path builder
parse.fastpaths(lib/parse.js). Itscreate()helper strips a trailing.extin thedefaultbranch and recurses on the remaining base. For**.thing.jsthe base is reduced to a bare**, which hits thecase '**'branch and expands to a globstar ((?:(?!...).)*?) that crosses/.Patterns like
**.dash-thing.jswere unaffected only by accident:-is not a\wcharacter, so they never matched the.extfast path and fell back to the full parser, which already produces the correct single-star regex.Fix
In the
defaultbranch, if stripping the extension reduces the base to a bare**, bail out of the fast path (return) and let the full parser handle the pattern — exactly the path that already produced correct output for**.dash-thing.js. This keeps the change minimal and guarantees the fast path agrees with the full parser.Tests
Added a regression test in
test/issue-related.js. The full suite passes (npm test): 1976 passing, including the existing globstar / "non-exclusive double-stars" specs.