Merge commit from fork · micromatch/picomatch@5eceecd · GitHub
Skip to content

Commit 5eceecd

Browse files
danezdoowb
andauthored
Merge commit from fork
* fix: add option for maximum nested extglobs with default depth of 2 Also find other risky globs and treat them as literals * Update test/options.maxExtglobRecursion.js Co-authored-by: Brian Woodward <brian.woodward@gmail.com> * Fix bug for single character nested star-only extglobs * Move constant to constants.js and set to 0 by default --------- Co-authored-by: Brian Woodward <brian.woodward@gmail.com>
1 parent 0db7dd7 commit 5eceecd

5 files changed

Lines changed: 453 additions & 0 deletions

File tree

‎.verb.md‎

Lines changed: 8 additions & 0 deletions

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ The following options may be used with the main `picomatch()` function or any of
345345
| `literalBrackets` | `boolean` | `undefined` | When `true`, brackets in the glob pattern will be escaped so that only literal brackets will be matched. |
346346
| `matchBase` | `boolean` | `false` | Alias for `basename` |
347347
| `maxLength` | `number` | `65536` | Limit the max length of the input string. An error is thrown if the input string is longer than this value. |
348+
| `maxExtglobRecursion` | `number\|boolean` | `0` | Limit nested quantified extglobs and other risky repeated extglob forms. When the limit is exceeded, the extglob is treated as a literal string instead of being compiled to regex. Set to `false` to disable this safeguard. |
348349
| `nobrace` | `boolean` | `false` | Disable brace matching, so that `{a,b}` and `{1..3}` would be treated as literal characters. |
349350
| `nobracket` | `boolean` | `undefined` | Disable matching with regex brackets. |
350351
| `nocase` | `boolean` | `false` | Make matching case-insensitive. Equivalent to the regex `i` flag. Note that this option is overridden by the `flags` option. |
@@ -554,6 +555,13 @@ console.log(pm.isMatch('foo.bar', '!(foo).!(bar)')); // false
554555
555556
// supports nested extglobs
556557
console.log(pm.isMatch('foo.bar', '!(!(foo)).!(!(bar))')); // true
558+
559+
// risky quantified extglobs are treated literally by default
560+
console.log(pm.makeRe('+(a|aa)'));
561+
//=> /^(?:\+\(a\|aa\))$/
562+
563+
// increase the limit to allow a small amount of nested quantified extglobs
564+
console.log(pm.isMatch('aaa', '+(+(a))', { maxExtglobRecursion: 1 })); // true
557565
```
558566
559567
#### POSIX brackets

‎lib/constants.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const WIN_SLASH = '\\\\/';
44
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
55

6+
const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
7+
68
/**
79
* Posix glob regex
810
*/
@@ -86,6 +88,7 @@ const POSIX_REGEX_SOURCE = {
8688
};
8789

8890
module.exports = {
91+
DEFAULT_MAX_EXTGLOB_RECURSION,
8992
MAX_LENGTH: 1024 * 64,
9093
POSIX_REGEX_SOURCE,
9194

‎lib/parse.js‎

Lines changed: 301 additions & 0 deletions

0 commit comments

Comments
 (0)