fix: allow globstars to match paths containing newlines - #202
Merged
Conversation
The globstar pattern previously used '.' in its negative lookahead loop,
which failed to match paths containing newline characters ('\n' or '\r').
Since single star '*' uses '[^/]*?' (which matches newlines), '**' was
failing to match a superset of '*'.
Replacing '.' with '[\s\S]' ensures globstars match any character while
preserving all dotfile and slash anchoring rules.
There was a problem hiding this comment.
Pull request overview
This PR fixes a regex edge case in picomatch’s globstar (**) parsing so that globstars can match paths containing newline characters, aligning globstar behavior with single-star matching on platforms where newlines are valid filename characters.
Changes:
- Update the
globstarregex generator inlib/parse.js(both full parse andfastpaths) to use[\s\S]instead of.so matches include line terminators. - Add regression tests covering globstar matches against path strings containing
\n.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/globstars.js | Adds regression tests for globstar matching when path segments contain newline characters. |
| lib/parse.js | Adjusts globstar regex generation to match any character including line terminators, fixing ** newline behavior (and mirroring the change in fastpaths). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+438
to
+441
| assert(isMatch('hello\nworld', '**')); | ||
| assert(isMatch('foo/hello\nworld', '**/*')); | ||
| assert(isMatch('foo\nbar/bar', '**/bar')); | ||
| assert(isMatch('foo\nbar/baz\nqux', '**/**')); |
Contributor
Author
There was a problem hiding this comment.
Added \r and \r\n test cases to verify full line-terminator coverage in 1470a59.
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.
Summary
Ensures globstar (
**) patterns correctly match file paths containing newline characters (\nor\r), aligning globstar behavior with single-star (*) wildcards and POSIX/Unix filesystem semantics.Root Cause
The
globstargenerator inlib/parse.jsused.inside its negative-lookahead loop:`(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`In JavaScript RegExp without the
s(dotAll) flag,.does not match line terminators (\n,\r,\u2028,\u2029). Meanwhile, single-star*uses[^/]*?which matches any character except/(including newlines). As a result,**unexpectedly failed to match a superset of*on valid Unix paths containing newlines.Changes
.with[\s\S]in theglobstar()helper across both full parse and fastpath paths (lib/parse.js).test/globstars.js).Verification
npm test: 1,997/1,997 tests pass (1,996 existing + 1 regression suite coveringhello\nworld,foo/hello\nworld, etc.).