Detect comments in jinja templates (#39496)

This commit is contained in:
Paulus Schoutsen 2020-08-31 10:51:30 +02:00 committed by GitHub
parent 00eb23b43f
commit 190611a079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -52,7 +52,7 @@ _RE_GET_ENTITIES = re.compile(
re.I | re.M,
)
_RE_JINJA_DELIMITERS = re.compile(r"\{%|\{\{")
_RE_JINJA_DELIMITERS = re.compile(r"\{%|\{\{|\{#")
_RESERVED_NAMES = {"contextfunction", "evalcontextfunction", "environmentfunction"}

View File

@ -2279,3 +2279,12 @@ async def test_cache_garbage_collection():
assert not template._NO_HASS_ENV.template_cache.get(
template_string
) # pylint: disable=protected-access
def test_is_template_string():
"""Test is template string."""
assert template.is_template_string("{{ x }}") is True
assert template.is_template_string("{% if x == 2 %}1{% else %}0{%end if %}") is True
assert template.is_template_string("{# a comment #} Hey") is True
assert template.is_template_string("1") is False
assert template.is_template_string("Some Text") is False