Skip to content

Ignore option does not work with lowercase drive letter (Windows) #527

@frankkulak

Description

@frankkulak

My VS Code extension accepts user-defined include/exclude patterns. I resolve relative paths with path.resolve(...), then convert all \\ to / with absPath.replace(/\\/g, "/") (I've been burned by using \\ in glob pattern on Windows in the past, figured out that glob requires / everywhere from this S/O post).

I then find matches like so:

// include/exclude are string arrays
const matches = glob.sync(include, {
  ignore: exclude,
});

This mostly works as expected (no issues on macOS), and even works on Windows if the user's excluded path is absolute, with an uppercase drive letter. The issue comes up when the user's path is relative, because resolving (which includes normalizing) the paths returns lowercase drive letters on Windows (EDIT: Just discovered that resolving does not lowercase the drive name; the lowercase is from how VS Code returns the root directory path).

This lowercase drive letter works fine for included patterns, it returns all of the paths I'd expect to see. However, the lowercase letter causes the ignored patterns to not work as I would expect, given that it does work with the included paths.

For example, I would expect the following to match all non-XML files within the source folder:

"include": [
  "**/*"
],
"exclude": [
  "**/*.xml"
]

These relative paths resolve to "include": ["c:/blah/**/*"] and "exclude": ["c:/blah/**/*.xml"], and using these paths as illustrated by my first code snippet returns every single file within blah, including *.xml ones.

However, if I instead use:

"include": [
  "**/*"
],
"exclude": [
  "C:/blah/**/*.xml"
]

It works as expected, and all XML files are excluded from the results.

For the time being, I suppose I can just add a hack that forces the drive letter to uppercase on Windows, but since the lowercase letter works in included patterns, I would expect it to also work in ignored ones. Is there a technical reason why this is not the case, or is this a bug? If it's intentional, do you have any best practices for using relative paths in the way I've described?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions