Skip to content

fix: format paths before basename matching - #225

Draft
vhinayindia wants to merge 1 commit into
micromatch:masterfrom
vhinayindia:fix/format-before-basename
Draft

vhinayindia wants to merge 1 commit into
micromatch:masterfrom
vhinayindia:fix/format-before-basename

Conversation

@vhinayindia

Copy link
Copy Markdown

Summary

Apply options.format before extracting the basename when basename or its matchBase alias is enabled.

The format documentation says strings are formatted before matching. picomatch.test() already calculates the formatted output, but currently passes the original input to matchBase():

const pm = require('picomatch');
const options = { basename: true, format: str => str.toLowerCase() };

pm.isMatch('SRC/FILE.JS', '*.js', options); // false; expected true
pm.isMatch('SRC/FILE.JS', '*.JS', options); // true; expected false
pm.isMatch('SRC/FILE.JS', '*', { ...options, ignore: '*.js' }); // true; expected false

Use that already-formatted output for basename matching, just as the full-path regex branch does. Reject an empty formatted basename so it cannot be coerced into the string undefined. This also lets callbacks normalize path separators before the basename is extracted. The original input and full formatted output remain available in match results.

Validation

Reproduced on current master 9fab7bf (picomatch 4.0.7), Linux, Node 24.19.0, with synthetic strings only.

  • Eight bug regressions fail before the production change and pass afterward. Two additional tests cover empty formatted basenames and fail without the empty-output guard.
  • Both option aliases are covered for positive/negative matches, separator normalization, ignored patterns, one formatter call, and result/callback metadata.
  • npm test: ESLint passes, 2,008 tests pass.
  • npm run test:ci: 2,008 tests pass with coverage.
  • git diff --check: clean.

The full Node/OS CI matrix has not been run locally. No dependency changes.

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.

1 participant