Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index outside the array bounds for nth filter #650

Open
rootkea opened this issue Jul 7, 2021 · 5 comments
Open

index outside the array bounds for nth filter #650

rootkea opened this issue Jul 7, 2021 · 5 comments

Comments

@rootkea
Copy link
Contributor

rootkea commented Jul 7, 2021

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.

@Keats
Copy link
Owner

Keats commented Jul 7, 2021

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.

@rootkea
Copy link
Contributor Author

rootkea commented Jan 2, 2022

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

@Keats
Copy link
Owner

Keats commented Jan 2, 2022

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

@rootkea
Copy link
Contributor Author

rootkea commented Jan 2, 2022

Instead throw an error like "Out of bounds"?

+1 to that!

@Keats
Copy link
Owner

Keats commented Jan 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants