fix: apply OS detection when called without an options object - #195
Open
yhuikzdtguioaert wants to merge 1 commit into
Open
fix: apply OS detection when called without an options object#195yhuikzdtguioaert wants to merge 1 commit into
yhuikzdtguioaert wants to merge 1 commit into
Conversation
picomatch()'s default OS detection was guarded on `options` being
truthy, so it was skipped when the matcher was created without an
options object. As a result `picomatch(glob)` and `picomatch(glob, {})`
disagreed about backslash handling on Windows. Default `windows` when
no options object is given too; explicit values are still respected.
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.
Fixes #133.
Problem
The default entry point auto-detects the OS to choose a default for the
windowsoption, but that detection is skipped whenpicomatch()is called without an options object. The result then depends on whether an (empty) options object is passed:Both calls should behave the same.
Cause
In
index.jsthe guard requiresoptionsto be truthy before defaultingwindows:When
optionsisundefinedthe whole condition isfalse, sowindowsis never defaulted and the matcher falls back to posix behavior even on Windows.Fix
Also apply the default when no options object is given.
{ ...undefined }is an empty object, so the existing spread keeps working and the caller's object is never mutated. An explicitwindows: true/windows: falseis still respected.Tests
Added two cases under
options.windowsintest/options.js. They stubutils.isWindowsso the behavior is asserted deterministically on any platform (the first case fails without this change). Full suite is green (1979 passing).