Skip to content

Commit

Permalink
Merge branch 'CrowCpp:master' into cors
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er authored Jan 7, 2025
2 parents 132b137 + 8dff896 commit 0c33f5d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ html/

#VS-Code
.vscode
.idea
cmake-build-debug
.cache
site
venv
7 changes: 7 additions & 0 deletions include/crow/mustache.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,13 @@ namespace crow // NOTE: Already documented in "crow/app.h"
while (body_[endIdx - 1] == ' ')
endIdx--;
{
if (blockPositions.empty())
{
throw invalid_template_exception(
std::string("unexpected closing tag: ")
+ body_.substr(idx, endIdx - idx)
);
}
auto& matched = actions_[blockPositions.back()];
if (body_.compare(idx, endIdx - idx,
body_, matched.start, matched.end - matched.start) != 0)
Expand Down
4 changes: 2 additions & 2 deletions tests/fuzz/template_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, const std::size_
auto ctx = build_context_object(fdp);
page.render_string(ctx);
}
catch (const crow::mustache::invalid_template_exception& e)
catch (const std::exception& e)
{
return -1;
// No special handling for invalid inputs or rendering errors
}

return 0;
Expand Down
9 changes: 9 additions & 0 deletions tests/template/crow_extra_mustache_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
},
"template": "\"{{#boolean}}{{^boolean}}\"",
"expected": "COMPILE EXCEPTION: crow::mustache error: open tag has no matching end tag {{# {{/ pair: boolean"
},
{
"name": "Unexpected end-tags",
"desc": "Unexpected end-tags should fail to render ... and not enter infinite loops or other undefined behaviour",
"data": {
"boolean": true
},
"template": "\"{{/unexpected}}\"",
"expected": "COMPILE EXCEPTION: crow::mustache error: unexpected closing tag: unexpected"
}
],
"__ATTN__": "This file was hand-written"
Expand Down

0 comments on commit 0c33f5d

Please sign in to comment.