Length filter does not work directly on strings
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 45/100
Research direction
Start at src/filters.cpp around line 457 and inspect how SequenceAccessor::Filter converts the input. Review the Length cases in test/filters_test.cpp around line 163, then run the filter tests; done means the direct string length expression renders the expected length without regressing list handling.
Written by the indexing model from the issue text.
Description
In jinja2, you can apply the length filter directly on strings like: {{ my_string | length }}, this will produce an empty value in jinja2Cpp.
The fix seems to be as simple as changing filters.cpp:457
diff --git a/src/filters.cpp b/src/filters.cpp
--- a/src/filters.cpp
+++ b/src/filters.cpp
@@ -454,7 +454,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
InternalValue result;
bool isConverted = false;
- ListAdapter list = ConvertToList(baseVal, isConverted);
+ ListAdapter list = ConvertToList(baseVal, isConverted, false);
if (!isConverted)
return result;
And adding a test:
diff --git a/test/filters_test.cpp b/test/filters_test.cpp
--- a/test/filters_test.cpp
+++ b/test/filters_test.cpp
@@ -161,6 +161,7 @@ INSTANTIATE_TEST_SUITE_P(Length, FilterGenericTest, ::testing::Values(
InputOutputPair{"intValue | length", ""},
InputOutputPair{"intList | length", "10"},
InputOutputPair{"stringValue | list | length", "4"},
+ InputOutputPair{"stringValue | length", "4"},
InputOutputPair{"reflectedIntVector | length", "10"}
));
- 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