fix: escape square brackets in glob paths - #920
Open
tzh476 wants to merge 2 commits into
Open
Conversation
Resolved dirs such as [Resource] or [a-z] were passed to picomatch as character classes, so the watcher skipped matching files. Escape [] the same way parentheses are already escaped. Change-Id: I6f7df301ff794b36e009767ce090ceb22ac07c3c Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
commit: |
…orking
Extending escapeSpecialChars to brackets, as this PR originally did, escapes the
whole joined path -- including the part that comes from the user's `dirs` option.
That turns a deliberate character class into a literal:
dirs: ['src/[ab]'] -> /proj/src/[ab]/**/*.vue matches /proj/src/a true
/proj/src/\[ab\]/**/*.vue matches /proj/src/a false
Verified with picomatch against the exact glob options.ts builds.
Escape only the `root` prefix instead. That is a real filesystem path, so its
parentheses and brackets are always literal, while everything after it is left as
the user wrote it.
Three tests added; the two behavioural ones fail with the previous implementation:
- a character class after the root still matches multiple directories
- the same under a root containing parentheses, so both hold at once
Note: test/dts.test.ts has 7 failures on this branch, but they reproduce on the
branch with these three files reverted, so they are pre-existing and unrelated.
Change-Id: I430acfc4eef4ecc2ef353a3fb46daf2ee98f93bf
Signed-off-by: tzh476 <tzh476@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Escape
[]in resolved component globs so directories like[Resource]or[a-z]match in the watcher.Why
escapeSpecialCharsonly escaped().resolveOptionsbuilds globs from absolute dirs, so a folder named[Resource]becomes a picomatch character class. Range-like names such as[a-z]still fail to match the real path (picomatch 4 treats some non-range brackets as literals, which is likely why #913 was closed as no longer needed — the range case remains broken).How
Extend the escape regex from
/[()]/gto/[()[\]]/g.matchGlobsthen receives a literal-bracket pattern.Testing
vitest run test/utils.test.tsmatchGlobs('/.../[a-z]/.../Button.vue', [unescaped glob])isfalsetrue[Foo]as requestedFixes #810
Made with Cursor