tera
tera copied to clipboard
index outside the array bounds for `nth` filter
What should happen if the index falls outside the array bounds?
- return empty string OR
- error
At present, nth(n=-1) gives error while nth(n=100) gives empty string (for array having length < 100). This is inconsistent behavior.
It gives an error because only positive integers are allowed and we're trying to cast n as usize. Otherwise it's always an empty string.
That I understand.
But may be we should return empty string if n < 0 (before cast)?
This makes it consistent with the case of n > array_size - 1.
So that, nth filter will return empty string if n falls outside the array bounds (in either direction).
I'm wondering if this behaviour of returning the empty string should be removed entirely in Tera v2.
Instead throw an error like "Out of bounds"?
+1 to that!
yes, although probably with some kind of required/default parameters