diff options
| author | Georg Brandl <georg@python.org> | 2020-12-17 08:03:20 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2020-12-17 08:03:20 +0100 |
| commit | a56ed8a1f2eb0db14aad50cb7e4eaaf7f2f0d3b3 (patch) | |
| tree | ea548a3807caee51edceec97e9bb301117fc3882 | |
| parent | 7958cd6c53215ac2caeb6812aaeab5e8029a43ad (diff) | |
| download | pygments-git-a56ed8a1f2eb0db14aad50cb7e4eaaf7f2f0d3b3.tar.gz | |
Limit recursion with nesting Ruby heredocs
fixes #1638
| -rw-r--r-- | CHANGES | 1 | ||||
| -rw-r--r-- | pygments/lexers/crystal.py | 7 | ||||
| -rw-r--r-- | pygments/lexers/ruby.py | 7 |
3 files changed, 11 insertions, 4 deletions
@@ -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 diff --git a/pygments/lexers/crystal.py b/pygments/lexers/crystal.py index cf051536..05171c9c 100644 --- a/pygments/lexers/crystal.py +++ b/pygments/lexers/crystal.py @@ -57,8 +57,11 @@ class CrystalLexer(ExtendedRegexLexer): 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: diff --git a/pygments/lexers/ruby.py b/pygments/lexers/ruby.py index e16cd711..d1ae5aff 100644 --- a/pygments/lexers/ruby.py +++ b/pygments/lexers/ruby.py @@ -57,8 +57,11 @@ class RubyLexer(ExtendedRegexLexer): 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: |
