fix: search in open editors for files with square brackets in names #270625
+26
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Files with square brackets in their names (e.g.,
foo[.js
,component[id].tsx
) leads to unexpected error when using "Search Only in Open Editors" because square brackets were interpreted as glob character classes instead of literal characters.Fixes #233049
Root Cause
When "Search Only in Open Editors" builds search queries, it creates include patterns from open file paths to restrict search scope. However, these file paths were used directly as glob patterns without escaping special characters. Square brackets [...] have special meaning in glob syntax - they define character classes that match any single character from the bracketed set. So a file named component[id].tsx created the pattern component[id].tsx, which the glob matcher interpreted as "component" + (any character from {i,d}) + ".tsx", failing to match the literal filename component[id].tsx.
Solution
Applied the existing escapeGlobPattern function to file paths before adding them to include patterns in the commonQueryFromFileList method. This function escapes special glob characters by wrapping them in brackets - converting component[id].tsx to component[[]id[]].tsx, where [[] represents a literal opening bracket and []] represents a literal closing bracket. The escaped pattern now matches the literal filename correctly. Added comprehensive tests to verify the fix handles square brackets properly without breaking existing functionality.