Repository navigation
feat: add an opt-in nesting depth limit - #77
Closed
Adam-Aghili wants to merge 1 commit into
Closed
Adam-Aghili wants to merge 1 commit into
Adam-Aghili wants to merge 1 commit into
Conversation
4 tasks
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.
Summary
Add an optional
maxDepthsetting for brace and parenthesis nesting. The setting is enforced while parsing strings and while walking caller-supplied ASTs throughcompile(),expand(), andstringify().The option is deliberately opt-in: leaving it undefined preserves the existing 3.0.3 behavior and output for normal callers. Invalid values are rejected as a non-negative integer contract.
Behavior
parse(pattern, { maxDepth: n })throwsSyntaxErrorbefore accepting a delimiter beyondn.compile(ast, { maxDepth: n }),expand(ast, { maxDepth: n }), andstringify(ast, { maxDepth: n })throwRangeErrorwhen an AST container exceedsn.expand()carries the active depth into invalid/dollar and empty-range stringify fallbacks, so caller-supplied subtrees cannot reset the limit by being stringified independently.escapeInvalid, range expansion, glob patterns, and direct AST APIs remain unchanged when the option is omitted.This is a bounded traversal control for callers that have a trust boundary. It does not claim to cap regular-expression compiler state, expansion cardinality, or every resource-exhaustion pattern, and it is not a universal fix for regex denial of service.
Tests
maxDepth: 100is supplied.npm testpasses with 900 tests on Node 22.22.0.Downstream note
Consumers must explicitly pass the option. In particular, chokidar 3.6.0 calls
braces.expand(path)without options, while micromatch's ordinary matching path uses picomatch. A published release and parent-package configuration are required before this option can affect those dependency paths.