Skip to content

Commit

Permalink
SQL+Jinja: use a simpler regex in analyse_text
Browse files Browse the repository at this point in the history
Fixes catastrophic backtracking

Fixes #2355
  • Loading branch information
jeanas committed Mar 1, 2023
1 parent 5f8c541 commit 97eb3d5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Version 2.15.0
parameters (#2359), improve lexing of variable variable syntax (#2358)
* Python: add missing builtins (#2334)
* Spice: update keywords (#2336)
* SQL+Jinja (``analyse_text`` method): fix catastrophic backtracking

- Declare support for Python 3.11 and drop support for Python 3.6 (#2324).
- Update ``native`` style to improve contrast (#2325).
Expand Down
6 changes: 1 addition & 5 deletions pygments/lexers/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,10 +2291,6 @@ def analyse_text(text):
if re.search(r'\{\{\s*source\(.*\)\s*\}\}', text):
rv += 0.25
# Jinja macro
if re.search(
r'\{%-?\s*macro \w+\(.*\)\s*-?%\}\s+.*\s+\{%-?\s*endmacro\s*-?%\}',
text,
re.S,
):
if re.search(r'\{%-?\s*macro \w+\(.*\)\s*-?%\}', text):
rv += 0.15
return rv

0 comments on commit 97eb3d5

Please sign in to comment.