Skip to content

Commit

Permalink
Limit recursion with nesting Ruby heredocs
Browse files Browse the repository at this point in the history
fixes #1638
  • Loading branch information
birkenfeld committed Dec 17, 2020
1 parent 7958cd6 commit a56ed8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -18,6 +18,7 @@ Version 2.7.4

- Fixed infinite loop in SML lexer (#1625)
- Fixed backtracking string regexes in JavaScript/TypeScript lexers (#1637)
- Limit recursion with nesting Ruby heredocs (#1638)


Version 2.7.3
Expand Down
7 changes: 5 additions & 2 deletions pygments/lexers/crystal.py
Expand Up @@ -57,8 +57,11 @@ def heredoc_callback(self, match, ctx):

ctx.pos = match.start(5)
ctx.end = match.end(5)
# this may find other heredocs
yield from self.get_tokens_unprocessed(context=ctx)
# this may find other heredocs, so limit the recursion depth
if len(heredocstack) < 100:
yield from self.get_tokens_unprocessed(context=ctx)
else:
yield ctx.pos, String.Heredoc, match.group(5)
ctx.pos = match.end()

if outermost:
Expand Down
7 changes: 5 additions & 2 deletions pygments/lexers/ruby.py
Expand Up @@ -57,8 +57,11 @@ def heredoc_callback(self, match, ctx):

ctx.pos = match.start(5)
ctx.end = match.end(5)
# this may find other heredocs
yield from self.get_tokens_unprocessed(context=ctx)
# this may find other heredocs, so limit the recursion depth
if len(heredocstack) < 100:
yield from self.get_tokens_unprocessed(context=ctx)
else:
yield ctx.pos, String.Heredoc, match.group(5)
ctx.pos = match.end()

if outermost:
Expand Down

0 comments on commit a56ed8a

Please sign in to comment.