Visitar URL original
Backslashes do not work on Windows after switch to fast-glob · Issue #1246 · shelljs/shelljs · GitHub
Skip to content

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

Description

@BrendanC23

The switch to fast-glob broke the handling of paths with backslashes on Windows.

This seems to be 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 test passes with previous versions but now fails:

test('cp with Windows-style backslash and glob pattern', t => {
  const result = shell.cp('test\\resources\\file*.txt', t.context.tmp);
  t.falsy(shell.error());
  t.falsy(result.stderr);
  t.is(result.code, 0);
  t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
  t.truthy(fs.existsSync(`${t.context.tmp}/file2.txt`));
});

One workaround is to change this line to the following:

ret = glob.sync(glob.convertPathToPattern(convertQuestionMarkForGlob(listEl)), globOpts);

This fixes this specific test case, I'm not sure if this will cause problems in other tests or on other platforms. I tried running all of the existing tests locally but ran into issues with different numbers of tests running each time. Even before making the change, there were also many failing tests (on both Windows and WSL).

Also see shelljs/shx#245, which describes the same issue with the shx package.

Activity

  1. nfischer commented on Apr 16, 2026

    @nfischer
    Member

    Thanks so much for the investigation. Do you want to upload a PR with your test and fix? I can run it on the CI infra to see if it breaks any other tests.

  2. added theissue type on Apr 16, 2026
  3. added
    fixBug/defect, or a fix for such a problem
    on Apr 16, 2026
  4. BrendanC23 commented on Apr 17, 2026

    @BrendanC23
    Author

    I've created #1252. The two new tests both pass locally on Windows. Running npm test fails locally (before and after the change), so the new PR will need to run in CI to see if it breaks any other tests.

  5. gameroman commented on May 15, 2026

    @gameroman

    Since shelljs now requires Node 18, it might be a good idea to switch to tinyglobby, which is much smaller and faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixBug/defect, or a fix for such a problemglob

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions