jinja2cpp / jinja2cpp/Jinja2Cpp
Support 'None' literal syntax (example template crashes / segfault / stack-buffer-overflow on "Load" today)
- Dominant language
- C++
- Stars
- 600
- Forks
- 114
- PR merge metrics
- No merged PRs in 30d
Description
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(InternalValue(true));
case Token::False:
return std::make_shared(InternalValue(false));
+ case Token::None:
+ return std::make_shared(InternalValue(EmptyValue()));
case '(':
valueRef = ParseBracedExpressionOrTuple(lexer);
break;
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.