Skip to content

Commit

Permalink
tokenize: disallow zero-length matches
Browse files Browse the repository at this point in the history
  • Loading branch information
cebtenzzre committed Feb 8, 2025
1 parent 3f30c0f commit 96ebff4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/minja/minja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,11 @@ class Parser {
throw std::runtime_error("Unexpected block: " + keyword);
}
} else if (std::regex_search(it, end, match, non_text_open_regex)) {
if (!match.position()) {
if (match[0] != "{#")
throw std::runtime_error("Internal error: Expected a comment");
throw std::runtime_error("Missing end of comment tag");
}
auto text_end = it + match.position();
text = std::string(it, text_end);
it = text_end;
Expand Down
1 change: 1 addition & 0 deletions tests/test-syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ TEST(SyntaxTest, SimpleCases) {
EXPECT_THAT([]() { render("{% if 1 %}{% else %}", {}, {}); }, ThrowsWithSubstr("Unterminated if"));
EXPECT_THAT([]() { render("{% if 1 %}{% else %}{% elif 1 %}{% endif %}", {}, {}); }, ThrowsWithSubstr("Unterminated if"));
EXPECT_THAT([]() { render("{% filter trim %}", {}, {}); }, ThrowsWithSubstr("Unterminated filter"));
EXPECT_THAT([]() { render("{# ", {}, {}); }, ThrowsWithSubstr("Missing end of comment tag"));
}

EXPECT_EQ(
Expand Down

0 comments on commit 96ebff4

Please sign in to comment.