Skip to content

Commit

Permalink
fix: remove performance cliff for brace expransions regex
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Jan 7, 2022
1 parent 3325450 commit 5669fab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/utils/pattern.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ describe('Utils → Pattern', () => {

it('should return false for unfinished brace expansions', () => {
assert.ok(!util.isDynamicPattern('{'));
assert.ok(!util.isDynamicPattern('{'.repeat(999999)));
assert.ok(!util.isDynamicPattern('{a'));
assert.ok(!util.isDynamicPattern('{,'));
assert.ok(!util.isDynamicPattern('{a,'));
assert.ok(!util.isDynamicPattern('{a,b'));
assert.ok(!util.isDynamicPattern('{a' + ','.repeat(999999) + 'b'));
assert.ok(!util.isDynamicPattern('{1..'));
assert.ok(!util.isDynamicPattern('{1.' + '.'.repeat(999999) + '2'));
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/utils/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[[^[]*]/;
const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\([^(]*\|[^|]*\)/;
const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/;
const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/;
const BRACE_EXPANSIONS_SYMBOLS_RE = /{[^,.{]*(?:,|\.\.)[^,.{]*}/;

type PatternTypeOptions = {
braceExpansion?: boolean;
Expand Down

0 comments on commit 5669fab

Please sign in to comment.