Skip to content

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

@BrendanC23

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixBug/defect, or a fix for such a problemglob

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions