fix(formatter): fix to prevent formatter from breaking malformed attribute tags

closes #317
This commit is contained in:
Christopher Pickering 2022-08-01 07:56:29 -05:00
parent 69ef16afa8
commit 80263b29bd
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 14 additions and 6 deletions

View file

@ -486,22 +486,22 @@ class Config:
) )
self.attribute_pattern: str = ( self.attribute_pattern: str = (
r""" r"""
(?:[^\s]+?=(?:\"[^\"]*?""" (?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?"""
+ self.template_if_for_pattern + self.template_if_for_pattern
+ r"""[^\"]*?\"|\'[^\']*?""" + r"""[^\"]*?\"|\'[^\']*?"""
+ self.template_if_for_pattern + self.template_if_for_pattern
+ r"""[^\']*?\')) + r"""[^\']*?\'))
| (?:[^\s]+?=(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\')) | (?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\'))
| """ | """
+ self.template_if_for_pattern + self.template_if_for_pattern
+ r""" + r"""
| (?:[^\s]+?=(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\")) | (?:[^\s]+?[ ]*?=[ ]*?(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\"))
| (?:[^\s]+?=(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\')) | (?:[^\s]+?[ ]*?=[ ]*?(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\'))
| (?:[^\s]+?=(?:\".*?\"|\'.*?\')) | (?:[^\s]+?[ ]*?=[ ]*?(?:\".*?\"|\'.*?\'))
| required | required
| checked | checked
| (?:\w|-|\.)+ | (?:\w|-|\.)+
| (?:\w|-|\.)+=(?:\w|-)+ | (?:\w|-|\.)+[ ]*?=[ ]*?(?:\w|-)+
| {{.*?}} | {{.*?}}
| {%.*?%} | {%.*?%}
""" """

View file

@ -83,6 +83,14 @@ def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
) )
assert output.exit_code == 0 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: def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat( output = reformat(