Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Length filter does not work directly on strings

Open
#273 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
tooling

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jinja2cpp/Jinja2Cpp

All issues in jinja2cpp/Jinja2Cpp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.