FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix handling of glob expansions for paths with a backslash by BrendanC23 · Pull Request #1252 · shelljs/shelljs · GitHub

Fix handling of glob expansions for paths with a backslash - #1252

Open
BrendanC23 wants to merge 4 commits into
shelljs:mainfrom
BrendanC23:backslash-fix
Open

Fix handling of glob expansions for paths with a backslash#1252
BrendanC23 wants to merge 4 commits into
shelljs:mainfrom
BrendanC23:backslash-fix

Conversation

Copy link
Copy Markdown

This PR adds convertPathToPattern to expand in common.js to 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:

Always use forward-slashes in glob expressions (patterns and ignore option).
Use backslashes for escaping characters.
[...]
Use the .convertPathToPattern package to convert Windows-style path to a Unix-style path.

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

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
Comment thread src/common.js Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comment thread test/cp.js Outdated
});

test('cp with Windows-style backslash and glob pattern', (t) => {
const result = shell.cp('test\\resources\\file*.txt', t.context.tmp);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

BrendanC23 commented Apr 21, 2026
edited
Loading

Copy link
Copy Markdown
Author

It looks like this is still breaking some other tests on Windows locally (ex: common.js tests for glob syntax, ? for single char in ... and config.globOptions respects nobrace). The former are fixed by swapping the calls to convertPathToPattern and convertQuestionMarkForGlob, but that doesn't fix the latter. I'll need to take a closer look at what's going wrong.

BrendanC23 marked this pull request as draft April 24, 2026 01:53
This commit switches to replacing `\\` in Windows with `/` instead
of using `convertPathToPattern`.
BrendanC23 marked this pull request as ready for review July 6, 2026 01:46
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backslashes do not work on Windows after switch to fast-glob

2 participants


Back | FazBrowse Home | New Git URL