Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 'None' literal syntax (example template crashes / segfault / stack-buffer-overflow on "Load" today) #264

Open
tjsmith-meta opened this issue Sep 25, 2024 · 0 comments

Comments

@tjsmith-meta
Copy link

Appears to work in Python jinja2, and there's a Note that mentions it in this section in the docs.
https://jinja.palletsprojects.com/en/2.10.x/templates/#literals

Here's a template example that works in Python and crashes on "Load" today.

{% set foo = None %}
{% if foo != None %}
1
{% else %}
None
{% endif %}
{% set bar = 1 %}
{% if bar != None %}
1
{% else %}
None
{% endif %}
{% set baz = none %}
{% if baz != none %}
1
{% else %}
none
{% endif %}
{% set qux = 1 %}
{% if qux != none %}
1
{% else %}
none
{% endif %}

This code change seemed to do the trick for me and seems to produce the correct output and no longer crash.

diff --git a/jinja2cpp/src/expression_parser.cpp b/jinja2cpp/src/expression_parser.cpp
--- a/jinja2cpp/src/expression_parser.cpp
+++ b/jinja2cpp/src/expression_parser.cpp
@@ -326,6 +326,8 @@
         return std::make_shared<ConstantExpression>(InternalValue(true));
     case Token::False:
         return std::make_shared<ConstantExpression>(InternalValue(false));
+    case Token::None:
+        return std::make_shared<ConstantExpression>(InternalValue(EmptyValue()));
     case '(':
         valueRef = ParseBracedExpressionOrTuple(lexer);
         break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant