Skip to content

Fix glob matching of Windows paths with backslashes - #1019

Open
Aaditya Jaiswar (aad1tyaaaaa) wants to merge 1 commit into
microsoft:mainfrom
aad1tyaaaaa:fix-glob-windows-separators
Open

Aaditya Jaiswar (aad1tyaaaaa) wants to merge 1 commit into
microsoft:mainfrom
aad1tyaaaaa:fix-glob-windows-separators

Conversation

@aad1tyaaaaa

Copy link
Copy Markdown

On Windows, glob patterns that go through the general matcher never match native paths, because slow_path compares bytes literally and a / in the pattern never equals a \ in the path. The **/name / **/*ext fast path (match_path_suffix) already treats the two as equal, so the result depends on which path a pattern takes.

As a result, files.associations keys such as Makefile.* (rewritten to **/Makefile.*) or **/.vscode/*.json don't apply on Windows:

glob_match("**/Makefile.*", r"C:\src\Makefile.am") // false, expected true

The Windows-aware comparison from match_path_suffix is now an eq_path_byte helper used by both paths. Behavior on other platforms is unchanged.

A new #[cfg(windows)] test covers the fast path, **/Makefile.*, **/.vscode/*.json, a/**/c against a\b\c, and a negative case (a*/b against a\c\b). It fails without the fix. cargo test -p lsh, cargo fmt --check and cargo clippy -p lsh --all-targets pass.

(Written with help from Claude Code.)

The fast path for `**/name` and `**/*ext` patterns already treats `\` and
`/` as equal on Windows, but the general matcher compared bytes literally.
Patterns like `**/Makefile.*` (e.g. from files.associations) therefore
never matched native Windows paths.
@DHowett

Copy link
Copy Markdown
Member

I would not expect file associations to validate paths at all. They apply to filenames. Why would they apply to full paths?

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.

2 participants