Indent filter crashes when passed unexpected input
Author: edwardhorsfordCreated Sep 4, 2025Updated Sep 4, 2025
I've found that the indent filter will crash Nunjucks if not passed a string.
Minimal test case:
{% set testArray = ['one', 'two'] %}
{# Crashes #}
{{ testArray | indent(8) }}The error returned is str.split is not a function
Why I think this is a bug
My general expectation with Nunjucks is that it fails gracefully. Usually if something isn't as expected it displays nothing and continues to render.
What I might have expected
I think I would have expected it to do one of:
- don't do anything - return original input
- don't do anything - return null / false / undefined
- cast to string and then indent
This isn't an issue for my project as I was only temporarily rendering it to check progress as I go. Many of our components use indent filter behind the scenes. I'll be updating the nunjucks to iterate over the array for display anyway.
Source: mozilla/nunjucks