Skip to content

Commit 96ebff4

Browse files
committed
tokenize: disallow zero-length matches
1 parent 3f30c0f commit 96ebff4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/minja/minja.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,6 +2336,11 @@ class Parser {
23362336
throw std::runtime_error("Unexpected block: " + keyword);
23372337
}
23382338
} else if (std::regex_search(it, end, match, non_text_open_regex)) {
2339+
if (!match.position()) {
2340+
if (match[0] != "{#")
2341+
throw std::runtime_error("Internal error: Expected a comment");
2342+
throw std::runtime_error("Missing end of comment tag");
2343+
}
23392344
auto text_end = it + match.position();
23402345
text = std::string(it, text_end);
23412346
it = text_end;

tests/test-syntax.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ TEST(SyntaxTest, SimpleCases) {
522522
EXPECT_THAT([]() { render("{% if 1 %}{% else %}", {}, {}); }, ThrowsWithSubstr("Unterminated if"));
523523
EXPECT_THAT([]() { render("{% if 1 %}{% else %}{% elif 1 %}{% endif %}", {}, {}); }, ThrowsWithSubstr("Unterminated if"));
524524
EXPECT_THAT([]() { render("{% filter trim %}", {}, {}); }, ThrowsWithSubstr("Unterminated filter"));
525+
EXPECT_THAT([]() { render("{# ", {}, {}); }, ThrowsWithSubstr("Missing end of comment tag"));
525526
}
526527

527528
EXPECT_EQ(

0 commit comments

Comments
 (0)