jinja icon indicating copy to clipboard operation
jinja copied to clipboard

Slice returns one extra item when slice count is a divisor of iterable length and fill_with not none

Open matiasilva opened this issue 4 months ago • 0 comments

The slice filter returns one extra item when the slice count can divide the iterable length completely and a fill_with value is used.

Example:

{% set a = [1, 2, 3, 4] %}
{{ a|slice(4, 'foo')|list }}

Output:

[[1, 'foo'], [2, 'foo'], [3, 'foo'], [4, 'foo']]

Expected output:

[[1], [2], [3], [4]]

Environment:

  • Python version: 3.10.12
  • Jinja version: 3.1.6

matiasilva avatar Oct 01 '25 16:10 matiasilva