mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-17 05:50:24 +00:00
fix(formatter): fix to prevent formatter from breaking malformed attribute tags
closes #317
This commit is contained in:
parent
69ef16afa8
commit
80263b29bd
2 changed files with 14 additions and 6 deletions
|
|
@ -486,22 +486,22 @@ class Config:
|
|||
)
|
||||
self.attribute_pattern: str = (
|
||||
r"""
|
||||
(?:[^\s]+?=(?:\"[^\"]*?"""
|
||||
(?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?"""
|
||||
+ self.template_if_for_pattern
|
||||
+ r"""[^\"]*?\"|\'[^\']*?"""
|
||||
+ self.template_if_for_pattern
|
||||
+ r"""[^\']*?\'))
|
||||
| (?:[^\s]+?=(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\'))
|
||||
| (?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\'))
|
||||
| """
|
||||
+ self.template_if_for_pattern
|
||||
+ r"""
|
||||
| (?:[^\s]+?=(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\"))
|
||||
| (?:[^\s]+?=(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\'))
|
||||
| (?:[^\s]+?=(?:\".*?\"|\'.*?\'))
|
||||
| (?:[^\s]+?[ ]*?=[ ]*?(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\"))
|
||||
| (?:[^\s]+?[ ]*?=[ ]*?(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\'))
|
||||
| (?:[^\s]+?[ ]*?=[ ]*?(?:\".*?\"|\'.*?\'))
|
||||
| required
|
||||
| checked
|
||||
| (?:\w|-|\.)+
|
||||
| (?:\w|-|\.)+=(?:\w|-)+
|
||||
| (?:\w|-|\.)+[ ]*?=[ ]*?(?:\w|-)+
|
||||
| {{.*?}}
|
||||
| {%.*?%}
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -83,6 +83,14 @@ def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
# attributes with space around = are not brocken
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<a href = "http://test.test:3000/testtesttesttesttesttesttesttesttesttest">Test</a>\n""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
|
|
|
|||
Loading…
Reference in a new issue