Fix handling of glob expansions for paths with a backslash#1252
Draft
BrendanC23 wants to merge 3 commits into
Draft
Fix handling of glob expansions for paths with a backslash#1252BrendanC23 wants to merge 3 commits into
BrendanC23 wants to merge 3 commits into
Conversation
This commit adds `convertPathToPattern` to `expand` in `common.js` to fix the handling of glob patterns for Windows file paths. The [switch to fast-glob](shelljs@13cfe8a) broke the handling of paths with backslashes on Windows. This is a limitation of the fast-glob library. From the [README](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#how-to-write-patterns-on-windows): >Always use forward-slashes in glob expressions (patterns and [ignore](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#ignore) option). Use backslashes for escaping characters. [...] Use the [.convertPathToPattern](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#convertpathtopatternpath) package to convert Windows-style path to a Unix-style path. Fixes shelljs#1246
nfischer
requested changes
Apr 19, 2026
| try { | ||
| ret = glob.sync(convertQuestionMarkForGlob(listEl), globOpts); | ||
| // Call convertPathToPattern to handle paths with backslashes | ||
| // See https://github.com/mrmlnc/fast-glob/blob/096a5b620f4224eb692bd8ff2c8de0e634e50d8e/README.md?plain=1#L658-L682 |
Member
There was a problem hiding this comment.
How about https://github.com/mrmlnc/fast-glob#convertpathtopatternpath instead?
| }); | ||
|
|
||
| test('cp with Windows-style backslash and glob pattern', (t) => { | ||
| const result = shell.cp('test\\resources\\file*.txt', t.context.tmp); |
Member
There was a problem hiding this comment.
I think you will need to wrap this test case with utils.skipOnUnix(t, () => { ... }. Check out test/which.js for an example of how this works.
Author
|
It looks like this is still breaking some other tests on Windows locally (ex: |
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.
This PR adds
convertPathToPatterntoexpandincommon.jsto fix the handling of glob patterns for Windows file paths.The switch to fast-glob broke the handling of paths with backslashes on Windows.
This is a limitation of the fast-glob library. From the README:
This PR includes tests for expand and cp that include paths with backslashes. Both of these tests fail without the fix and pass once the fix is added.
Fixes #1246