diff --git a/common/jinja/lexer.cpp b/common/jinja/lexer.cpp index 85eaa1a76b..a7876a42f8 100644 --- a/common/jinja/lexer.cpp +++ b/common/jinja/lexer.cpp @@ -259,6 +259,11 @@ lexer_result lexer::tokenize(const std::string & source) { // Check for numbers following the unary operator std::string num = consume_while(is_integer); + if (pos < src.size() && src[pos] == '.' && pos + 1 < src.size() && is_integer(src[pos + 1])) { + ++pos; // Consume '.' + std::string frac = consume_while(is_integer); + num += "." + frac; + } std::string value = std::string(1, ch) + num; token::type t = num.empty() ? token::unary_operator : token::numeric_literal; // JJ_DEBUG("consumed unary operator or numeric literal: '%s'", value.c_str()); diff --git a/tests/test-jinja.cpp b/tests/test-jinja.cpp index 7adb302ffb..0f49bdc84f 100644 --- a/tests/test-jinja.cpp +++ b/tests/test-jinja.cpp @@ -247,6 +247,12 @@ static void test_expressions(testing & t) { "Bob" ); + test_template(t, "negative float (not dot notation)", + "{{ -1.0 }}", + json::object(), + "-1.0" + ); + test_template(t, "bracket notation", "{{ user['name'] }}", {{"user", {{"name", "Bob"}}}},