Support 'None' literal syntax (example template crashes / segfault / stack-buffer-overflow on "Load" today)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start in jinja2cpp/src/expression_parser.cpp, where the issue identifies the literal-expression handling and provides a candidate change. Load the supplied template example and verify that it produces the expected output for None and none without crashing, including the existing integer comparisons.
Written by the indexing model from the issue text.
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<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;
- Dominant language
- C++
- Stars
- 600
- Forks
- 114
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jinja2cpp/Jinja2Cpp
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
All issues in jinja2cpp/Jinja2Cpp
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Icinga/icinga2#11058 · 1 comment ·
Maintainers usually reply within 1 day
-
component: split-view platform: windows
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
zen-browser/desktop#15616 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area/ysql kind/bug priority/medium status/awaiting-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yugabyte/yugabyte-db#34415 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
WayfireWM/wayfire#3148 · 1 comment ·
Maintainers usually reply within 1 day