split filter generates an empty list element if the string to be split ends or beings with the separator
I'm not sure whether this is an expected or desired behaviour - I've noticed this as a change compared to whatever version of tera zola 0.9 was using :)
{% set path = "/a/b/c/" %}
{{ path|split(pat='/') }}
returns
[a, b, c, ]
It's either a bug or undocumented behaviour :) Please pick one and adjust code or documentation as necessary :D
I just found a bug related to this - the empty (?) element throws off slicing:
{% set path="/a/b/c/" %}
{{ path|safe }}
{{ path|split(pat='/') }}
{{ path|split(pat='/')|slice(end=2) }}
{% set path="a/b/c" %}
{{ path|safe }}
{{ path|split(pat='/') }} {{ path|split(pat='/')|slice(end=2) }}
results in:
a/b/c
[a, b, c]
[a, b]
/a/b/c/
[a, b, c, ]
[a]
The results of those slices should be identical in first and second case.
Actually, the case where string starts with a separator is even more insidious - the element is not visible after stringification but affects the count. Here's a full set of tests:
{% set path="a/b/c/" %}
{{ path|safe }}
{{ path|split(pat='/') }}
{{ path|split(pat='/')|slice(end=2) }}
{% set path="/a/b/c" %}
{{ path|safe }}
{{ path|split(pat='/') }}
{{ path|split(pat='/')|slice(end=2) }}
{% set path="/a/b/c/" %}
{{ path|safe }}
{{ path|split(pat='/') }}
{{ path|split(pat='/')|slice(end=2) }}
{% set path="a/b/c" %}
{{ path|safe }}
{{ path|split(pat='/') }}
{{ path|split(pat='/')|slice(end=2) }}
results in:
a/b/c/
[a, b, c, ]
[a, b]
/a/b/c
[a, b, c]
[a]
/a/b/c/
[a, b, c, ]
[a]
a/b/c
[a, b, c]
[a, b]
The split filter is just the Rust split fn :/
I'm not sure what's the deal with the leading element missing.