tera icon indicating copy to clipboard operation
tera copied to clipboard

index outside the array bounds for `nth` filter

Open rootkea opened this issue 4 years ago • 5 comments

What should happen if the index falls outside the array bounds?

  1. return empty string OR
  2. error

At present, nth(n=-1) gives error while nth(n=100) gives empty string (for array having length < 100). This is inconsistent behavior.

rootkea avatar Jul 07 '21 18:07 rootkea

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.

Keats avatar Jul 07 '21 20:07 Keats

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).

rootkea avatar Jan 02 '22 07:01 rootkea

I'm wondering if this behaviour of returning the empty string should be removed entirely in Tera v2.

Keats avatar Jan 02 '22 14:01 Keats

Instead throw an error like "Out of bounds"?

+1 to that!

rootkea avatar Jan 02 '22 15:01 rootkea

yes, although probably with some kind of required/default parameters

Keats avatar Jan 02 '22 18:01 Keats