Code:
from jinja2 import Template
print(Template('{{ "2016.10.26_cc37528" | truncate(11, True) }}').render())
print(Template('{{ "2016.10.26_cc37528" | truncate(12, True) }}').render())
print(Template('{{ "2016.10.26_cc37528" | truncate(13, True) }}').render())
print(Template('{{ "2016.10.26_cc37528" | truncate(14, True) }}').render())
2016.10....
2016.10.2...
2016.10.26...
2016.10.26_...
2016.10....
2016.10.2...
2016.10.26_cc37528
2016.10.26_cc37528
{{ "2016.10.26_cc37528" | truncate(13, True) }}
Check whether this is caused by the leeway
argument. The default value for it changed recently.
https://github.com/pallets/jinja/blob/master/jinja2/filters.py#L467
It is. Setting leeway to 0 fixes the issue. I'd say it's POLA violation when using short strings.
Yeah I agree @AMDmi3 . We just hit this issue as well.
The problem is that Jinja has an opinionated implementation which is incompatible with usage as a general purpose templating engine.
I also found this problem and spend several hours finding the bug. Clearly new options should be backwards compatible and the default should be leeway = 0
.
Whoever starts using the new option leeway
they will know it exists and will use the value they please. Those who dont know about the new parameter wont need to change their code...
Most helpful comment
It is. Setting leeway to 0 fixes the issue. I'd say it's POLA violation when using short strings.