Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

template_parser: Fix Handlebars comment parsing.

Anders Kaseorg97600d849931
diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py
index b07ee141338..87306f5835d 100644
--- a/tools/lib/template_parser.py
+++ b/tools/lib/template_parser.py
@@ -72,7 +72,7 @@ def tokenize(text: str, template_format: str | None = None) -> list[Token]:
return looking_at("<!--")
def looking_at_handlebars_comment() -> bool:
- return looking_at("{{!")
+ return looking_at("{{!") or looking_at("{{~!")
def looking_at_djangocomment() -> bool:
return template_format == "django" and looking_at("{#")
@@ -737,10 +737,13 @@ def get_html_comment(text: str, i: int) -> str:
def get_handlebars_comment(text: str, i: int) -> str:
+ long = text[i : i + 5] == "{{!--" or text[i : i + 6] == "{{~!--"
end = i + 5
unclosed_end = 0
while end <= len(text):
- if text[end - 2 : end] == "}}":
+ if text[end - 2 : end] == "}}" and (
+ not long or text[end - 4 : end] == "--}}" or text[end - 5 : end] == "--~}}"
+ ):
return text[i:end]
if not unclosed_end and text[end] == "<":
unclosed_end = end