tools: Enforce '_html' suffix for unescaped hbs vars.

This adds a check to enforce the new convention of
raw HTML variables having a `_html` suffix for
better clarity.

Discussion: https://chat.zulip.org/#narrow/channel/92-learning/topic/Marking.20commits.20to.20be.20squashed.20in.20PRs
Signed-off-by: apoorvapendse <apoorvavpendse@gmail.com>
This commit is contained in:
apoorvapendse
2025-08-10 12:38:18 +05:30
committed by Tim Abbott
parent a935866601
commit 3188d9db31
3 changed files with 79 additions and 2 deletions

View File

@@ -179,7 +179,7 @@ BAD_HTML8 = """
{{#each test}}
{{#with this}}
{{#if foobar}}
<div class="anything">{{{test}}}</div>
<div class="anything">{{{test_html}}}</div>
{{/if}}
{{#if foobar2}}
{{> teststuff}}
@@ -192,7 +192,7 @@ GOOD_HTML8 = """
{{#each test}}
{{#with this}}
{{#if foobar}}
<div class="anything">{{{test}}}</div>
<div class="anything">{{{test_html}}}</div>
{{/if}}
{{#if foobar2}}
{{> teststuff}}

View File

@@ -147,6 +147,54 @@ class ParserTest(unittest.TestCase):
template_format="handlebars",
)
def test_validate_triple_stache_var_1(self) -> None:
my_html = """
{{{ foo}}
"""
self._assert_validate_error(
'Tag missing "}}}" at line 2 col 13:"{{{ foo}}\n"',
text=my_html,
template_format="handlebars",
)
def test_validate_triple_stache_var_2(self) -> None:
my_html = """
{{{ foo}~}
"""
self._assert_validate_error(
'Tag missing "}}}" at line 2 col 13:"{{{ foo}~}"',
text=my_html,
template_format="handlebars",
)
def test_validate_triple_stache_var_3(self) -> None:
my_html = """
{{{ foo }}}
"""
self._assert_validate_error(
"Unescaped variables in triple staches {{{ }}} must be suffixed with `_html`",
text=my_html,
template_format="handlebars",
)
def test_validate_triple_stache_var_4(self) -> None:
my_html = """
{{{ foo_html }~}}
"""
validate(text=my_html, template_format="handlebars")
def test_validate_triple_stache_var_5(self) -> None:
my_html = "{{{ foo_html}}}"
validate(text=my_html, template_format="handlebars")
def test_validate_triple_stache_var_6(self) -> None:
my_html = "{{~{ bar_html}}}"
validate(text=my_html, template_format="handlebars")
def test_validate_triple_stache_var_7(self) -> None:
my_html = "{{~{ bar_html}~}}"
validate(text=my_html, template_format="handlebars")
def test_validate_incomplete_django_tag_1(self) -> None:
my_html = """
{% foo