diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index eb3d507960..4b94a49d81 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -301,7 +301,21 @@ def validate(fn: Optional[str] = None, text: Optional[str] = None, check_indent: def is_special_html_tag(s: str, tag: str) -> bool: return tag in ['link', 'meta', '!DOCTYPE'] +OPTIONAL_CLOSING_TAGS = [ + 'br', + 'circle', + 'hr', + 'img', + 'input', + 'path', + 'polygon', +] + def is_self_closing_html_tag(s: Text, tag: Text) -> bool: + if s.endswith('/>'): + if tag in OPTIONAL_CLOSING_TAGS: + return True + raise TokenizationException('Singleton tag not allowed', tag) self_closing_tag = tag in [ 'area', 'base', @@ -316,8 +330,9 @@ def is_self_closing_html_tag(s: Text, tag: Text) -> bool: 'track', 'wbr', ] - singleton_tag = s.endswith('/>') - return self_closing_tag or singleton_tag + if self_closing_tag: + return True + return False def is_django_block_tag(tag: str) -> bool: return tag in [ diff --git a/tools/tests/test_html_branches.py b/tools/tests/test_html_branches.py index ccce328923..45dbafad32 100644 --- a/tools/tests/test_html_branches.py +++ b/tools/tests/test_html_branches.py @@ -41,7 +41,7 @@ class TestHtmlBranches(unittest.TestCase): -

Hello
world!

+

Hello
world!

Goodbyeworld!

@@ -83,7 +83,7 @@ class TestHtmlBranches(unittest.TestCase): -

Hello
world!

+

Hello
world!

Goodbyeworld!

diff --git a/tools/tests/test_pretty_print.py b/tools/tests/test_pretty_print.py index ec3f620221..efc250af12 100644 --- a/tools/tests/test_pretty_print.py +++ b/tools/tests/test_pretty_print.py @@ -20,7 +20,7 @@ BAD_HTML = """ -

Hello
world!

+

Hello
world!

Goodbyeworld!

@@ -52,7 +52,7 @@ GOOD_HTML = """ -

Hello
world!

+

Hello
world!

Goodbyeworld!

@@ -338,7 +338,7 @@ BAD_HTML13 = """ {{#if this.is_realm_emoji}} {{else}} -
+
{{/if}} {{/if}}
{{this.count}}
@@ -353,7 +353,7 @@ GOOD_HTML13 = """ {{#if this.is_realm_emoji}} {{else}} -
+
{{/if}} {{/if}}
{{this.count}}
diff --git a/tools/tests/test_template_parser.py b/tools/tests/test_template_parser.py index 894058251f..5928101e47 100644 --- a/tools/tests/test_template_parser.py +++ b/tools/tests/test_template_parser.py @@ -249,7 +249,7 @@ class ParserTest(unittest.TestCase): self.assertEqual(token.kind, 'html_start') self.assertEqual(token.tag, 'a') - tag = '
bla' + tag = '
bla' token = tokenize(tag)[0] self.assertEqual(token.kind, 'html_singleton') self.assertEqual(token.tag, 'br')