Skip to content

Commit

Permalink
fix(formatter): fixed overgrabbing on template tag condensing
Browse files Browse the repository at this point in the history
closes #686
  • Loading branch information
christopherpickering committed Jun 26, 2023
1 parent 5c75d87 commit 75c3134
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/djlint/formatter/condense.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def if_blank_line_before_match(config: Config, html: str) -> bool:
# jinja +%} and {%+ intentionally omitted.
html = re.sub(
re.compile(
rf"((?:\s|^){{%-?[ ]*?({config.optional_single_line_template_tags})(?:(?!\n|%}}).)*?%}})\s*([^%\n]*?)\s*?({{%-?[ ]+?end(\2)[ ]*?%}})",
rf"((?:\s|^){{%-?[ ]*?({config.optional_single_line_template_tags})\b(?:(?!\n|%}}).)*?%}})\s*([^%\n]*?)\s*?({{%-?[ ]+?end(\2)[ ]*?%}})",
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE,
),
func,
Expand Down
35 changes: 35 additions & 0 deletions tests/test_django/test_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,41 @@
),
id="test nested formfield",
),
pytest.param(
(
'<div class="form-inputs plans-form">\n'
' <div class="trans-wrapper pos-comparator-flex">\n'
" {% for field in POSOptimizer %}\n"
" <div>\n"
" <label>{{ field.label }}</label>\n"
" {% formfield field show_label=False %}\n"
" </div>\n"
" {% endfor %}\n"
" <div>\n"
" <label>&nbsp</label>\n"
' <button type="submit">{% trans "Calcola" %}</button>\n'
" </div>\n"
" </div>\n"
"</div>\n"
),
(
'<div class="form-inputs plans-form">\n'
' <div class="trans-wrapper pos-comparator-flex">\n'
" {% for field in POSOptimizer %}\n"
" <div>\n"
" <label>{{ field.label }}</label>\n"
" {% formfield field show_label=False %}\n"
" </div>\n"
" {% endfor %}\n"
" <div>\n"
" <label>&nbsp</label>\n"
' <button type="submit">{% trans "Calcola" %}</button>\n'
" </div>\n"
" </div>\n"
"</div>\n"
),
id="test nested formfield inside for",
),
]


Expand Down

0 comments on commit 75c3134

Please sign in to comment.