From 79cd013f8dfea25523b9682c2363d33d0d2c60ac Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 22 Aug 2022 11:59:19 -0500 Subject: [PATCH] fix(formatter): fixed runaway regex on templates with many template attriutes inside html tags closes #340 --- src/djlint/formatter/expand.py | 8 ++++---- src/djlint/rules.yaml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/djlint/formatter/expand.py b/src/djlint/formatter/expand.py index 9363304..4ea2d32 100644 --- a/src/djlint/formatter/expand.py +++ b/src/djlint/formatter/expand.py @@ -61,13 +61,13 @@ def expand_html(html: str, config: Config) -> str: if inside_ignored_block(config, html, match): return match.group(1) - if not re.findall( r"\<(?:" + str(config.indent_html_tags) - + r")\b(?:[^>]|{%[^(?:%}]*?%}|{{[^(?:}}]*?}})*?" - + re.escape(match.group(1)) - + "$", + + r")\b(?:\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{\#[^\#]*\#}|[^>{}])*?" + # original + # + r")\b(?:[^>]|{%[^(?:%}]*?%}|{{[^(?:}}]*?}})*?" + + re.escape(match.group(1)) + "$", html[: match.end()], re.MULTILINE | re.VERBOSE, ): diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index d1d2f5c..42fac5e 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -185,7 +185,7 @@ message: Tag seems to be an orphan. flags: re.I|re.DOTALL patterns: - - <((/?(\w+))\b(\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{#[^%]*#}|[^'\">{}])*)(? + - <((/?(\w+))\b(\"[^\"]*\"|'[^']*'|{{[^}]*}}|{%[^%]*%}|{#[^#]*#}|[^'\">{}])*)(? - rule: name: H026 message: Empty id and class tags can be removed.