Skip to content

fix: keep globstars before a pipe in parens (#147) - #224

Open
gyanu2507 wants to merge 1 commit into
micromatch:masterfrom
gyanu2507:fix/globstar-before-pipe-in-parens
Open

gyanu2507 wants to merge 1 commit into
micromatch:masterfrom
gyanu2507:fix/globstar-before-pipe-in-parens

Conversation

@gyanu2507

Copy link
Copy Markdown

Fixes #147

A /** right before a | inside a group was compiled as a single *, so the order of alternatives changed the result:

pm.isMatch('feature/test/test', '(feature/**|feature*)'); // false
pm.isMatch('feature/test/test', '(feature*|feature/**)'); // true

The same happened with extglobs. @(a/**|b) did not match a/b/c, and !(a/**|b) did match it.

Cause

The pipe handler pushes | as a text token. When push() sees a non-boundary token right after a globstar, it demotes the globstar to a single star. Slashes, parens, braces and extglob tokens are exempt, but a pipe inside a group was not. The extglobs.length && tok.type === 'pipe' check was meant to cover this, but no token is ever created with type pipe, so it never ran. The last alternative worked only because ) is exempt.

Fix

  • In push(), treat a | inside parens as a boundary so the preceding globstar stays a globstar.
  • In the star handler, treat a globstar followed by | inside parens as the end of that alternative, the same way ** does not work when in parentheses #142 handles a globstar followed only by closing parens. So (feature/**|other) matches feature, same as (other|feature/**) and feature/**. Negated extglobs are still excluded from this, as in ** does not work when in parentheses #142.

The | token keeps type text, so parse() output is unchanged (the foo.(m|c|)js token test still passes).

Testing

Added a case to test/issue-related.js covering both orders for plain groups, @(), !(), matching the parent path, and dotfiles still being excluded.

  • npx mocha test/issue-related.js without the lib/parse.js change: 9 passing, 1 failing
  • With the change: 10 passing
  • npx mocha: 1999 passing
  • npm run lint: clean

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.

Inconsistent Matching Behavior Between (feature/**|feature*) and (feature*|feature/**) for feature/test/test

1 participant