allow variables starting with $ and @
diff --git a/include/inja/lexer.hpp b/include/inja/lexer.hpp
index e9a900f..e31c3d6 100644
--- a/include/inja/lexer.hpp
+++ b/include/inja/lexer.hpp
@@ -169,6 +169,8 @@
minus_state = MinusState::Operator;
return scan_number();
case '_':
+ case '@':
+ case '$':
minus_state = MinusState::Operator;
return scan_id();
default:
diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp
index 26a6373..516aa95 100644
--- a/single_include/inja/inja.hpp
+++ b/single_include/inja/inja.hpp
@@ -2049,6 +2049,8 @@
minus_state = MinusState::Operator;
return scan_number();
case '_':
+ case '@':
+ case '$':
minus_state = MinusState::Operator;
return scan_id();
default:
@@ -3435,6 +3437,10 @@
template<bool throw_not_found=true>
Arguments get_argument_vector(size_t N, const AstNode& node) {
+ if (json_eval_stack.size() < N) {
+ throw_renderer_error("function needs " + std::to_string(N) + " variables, but has only found " + std::to_string(json_eval_stack.size()), node);
+ }
+
Arguments result {N};
for (size_t i = 0; i < N; i += 1) {
result[N - i - 1] = json_eval_stack.top();
diff --git a/test/test-functions.cpp b/test/test-functions.cpp
index f903102..60c8b79 100644
--- a/test/test-functions.cpp
+++ b/test/test-functions.cpp
@@ -161,6 +161,8 @@
CHECK(env.render("{{ exists(\"zipcode\") }}", data) == "false");
CHECK(env.render("{{ exists(name) }}", data) == "false");
CHECK(env.render("{{ exists(property) }}", data) == "true");
+
+ // CHECK(env.render("{{ exists(\"keywords\") and length(keywords) > 0 }}", data) == "false");
}
SUBCASE("existsIn") {
diff --git a/test/test-renderer.cpp b/test/test-renderer.cpp
index 46935ef..8d5b447 100644
--- a/test/test-renderer.cpp
+++ b/test/test-renderer.cpp
@@ -16,6 +16,8 @@
data["brother"]["daughter0"] = {{"name", "Maria"}};
data["is_happy"] = true;
data["is_sad"] = false;
+ data["@name"] = "@name";
+ data["$name"] = "$name";
data["relatives"]["mother"] = "Maria";
data["relatives"]["brother"] = "Chris";
data["relatives"]["sister"] = "Jenny";
@@ -38,6 +40,8 @@
CHECK(env.render("Hello {{ brother.name }}!", data) == "Hello Chris!");
CHECK(env.render("Hello {{ brother.daughter0.name }}!", data) == "Hello Maria!");
CHECK(env.render("{{ \"{{ no_value }}\" }}", data) == "{{ no_value }}");
+ CHECK(env.render("{{ @name }}", data) == "@name");
+ CHECK(env.render("{{ $name }}", data) == "$name");
CHECK_THROWS_WITH(env.render("{{unknown}}", data), "[inja.exception.render_error] (at 1:3) variable 'unknown' not found");
}