fix: forward windows option to basename in matchBase#179
Open
chatman-media wants to merge 1 commit into
Open
Conversation
`picomatch.matchBase` stopped honoring the `windows` option after the switch from Node's `path.basename` to `utils.basename` (2f25761, "Remove automatic windows detection"). The `posix` argument that `picomatch.test` still passes was dropped from the signature, and `utils.basename(input)` was called without the `{ windows }` flag, so backslash-separated paths were never split into segments. As a result `isMatch('a\\b\\c\\foo.md', '*.md', { matchBase: true, windows: true })` returned `false` even though `utils.basename` already supports `{ windows: true }` (and is tested for it). Restore the `posix` parameter (defaulting to `options.windows`, as in `picomatch.test`) and pass it through to `utils.basename`.
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.
What
picomatch.matchBaseno longer honors thewindowsoption, so backslash-separated paths are not split into segments when matching a basename pattern with{ matchBase: true, windows: true }.Forward-slash paths work as expected; only backslash separators are affected.
Why
When
windows: true, the parser builds a regex whose path-segment class excludes both separators ([^\\/]), so a multi-segment backslash path likea\b\c\foo.mdcan't match a single-segment pattern like*.mddirectly. Matching then falls back topicomatch.matchBase, which is supposed to test the basename of the input.picomatch.teststill passes theposix/windows flag tomatchBase:but in #64 (commit
2f25761, "Remove automatic windows detection")matchBasewas changed from Node'spath.basenameto the internalutils.basename, and in the process:posixparameter was dropped from the signature, andutils.basename(input)was called without the{ windows }flag.utils.basenamealready supports{ windows: true }(and is covered by tests intest/regex-features.js), so without the flag it only ever splits on/. For a backslash path it returns the whole string, which then fails the regex.Fix
Restore the
posixparameter (defaulting tooptions.windows, mirroring howpicomatch.testderives it) and forward it toutils.basename:Minimal change; no behavior change for POSIX paths.
Tests
Added cases under
options.matchBaseintest/options.jscovering backslash-separated paths with{ matchBase: true, windows: true }and a directmatchBase(..., { windows: true })call. Verified they fail without the fix and pass with it. Full suite green (npm run mocha→ 1977 passing) andnpm run lintclean.