fix: escape meta characters in paths during brace expansion#108
Merged
bmatcuk merged 2 commits intobmatcuk:masterfrom Jan 10, 2026
Merged
fix: escape meta characters in paths during brace expansion#108bmatcuk merged 2 commits intobmatcuk:masterfrom
bmatcuk merged 2 commits intobmatcuk:masterfrom
Conversation
Add test cases that demonstrate the bug where brace expansion fails to match paths containing literal meta characters in directory names.
The following patterns fail to match correctly:
- e/**/{z,other} with e/[x]/[y]/z: brackets interpreted as character class
- f/\{a,b\}/{c,other} with f/{a,b}/c: braces interpreted as brace expansion
- f/\*/{a,other} with f/*/a: asterisk interpreted as wildcard (over-matches)
- f/\?/{a,other} with f/?/a: question mark interpreted as wildcard (over-matches)
These tests will pass once the fix for escaping meta characters in globAlts/buildAlt is implemented.
When processing brace expansion (e.g., `{a,b}`), the globAlts and doGlobAltsWalk functions build new patterns by combining filesystem paths with pattern fragments.
Previously, paths containing meta characters (e.g., `[orderID]`, `{a,b}`, `*`, `?`) were passed directly to buildAlt without escaping, causing them to be interpreted as glob patterns rather than literal path components.
This fix adds an escapeMeta function (the inverse of unescapeMeta) and applies it to filesystem-derived paths before building alternative patterns.
This ensures that:
- `[...]` in paths are not interpreted as character classes
- `{...}` in paths are not interpreted as brace expansions
- `*` and `?` in paths are not interpreted as wildcards
Also renamed metaReplacer to unescapeMetaReplacer for clarity.
Owner
|
Thanks! Looks like there were a couple tests that were broken: tests using |
Contributor
Author
|
Thanks a lot for fixing the CI issues and merging this PR. |
Owner
|
No worries! Glad you find it useful =) |
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.
Overview
This PR fixes an issue where brace expansion patterns (e.g.,
{a,b}) fail to match correctly when the directory path contains glob meta characters (*,?,[,],{,}).Problem
When using patterns like
e/**/{z,other}to match files in directories with meta characters (e.g.,e/[x]/[y]/z), the globbing would fail because the directory pathe/[x]/[y]was being passed tobuildAltwithout escaping, causing the meta characters to be interpreted as glob patterns rather than literal characters.Solution
escapeMetafunction inutils.goto escape meta characters in pathsglobAltsinglob.goanddoGlobAltsWalkinglobwalk.goto escape the directory pathdbefore passing it tobuildAltmetaReplacertounescapeMetaReplacerfor clarityTest cases added
e/**/{z,other}matchinge/[x]/[y]/z- directory with bracket charactersf/\{a,b\}/{c,other}matchingf/{a,b}/c- directory with literal bracesf/\*/{a,other}matchingf/*/a- directory with literal asterisk (non-Windows)f/\?/{a,other}matchingf/?/a- directory with literal question mark (non-Windows)