Open davide1993 opened 1 year ago
Please provide a template proof of concept or a test case to assist getting a resolution quickly. Based on the report, it seems you are accessing index > size of list or index < negative size of list.
You are right. This is my template myArray[0].myfield where myArray is empty. I want to resolve that field but when arrayIndex>array.length it throws an exception and the user see "Errore Liquid: Index was outside the bounds of the array." so I suggest to add an if condition for this scenario and set value to null or string.Empty.
so I suggest to add an if condition for this scenario and set value to null or string.Empty.
Do you have any reference test that indicates this is the behavior on Ruby Liquid? And if yes, which is it, null or empty? A test on replit would suffice.
See https://replit.com/@microalps/LiquidUnitTests#main.rb test named test_empty_array_index that indicates it returns an empty string. However, see also test_array_indexoutofbound that indicates this is even true when the array is of integers which might not be desired. @daviburg thoughts?
Dotliquid version
2.2.508
Expected behavior
value=null or value=string.Empty
Actual behavior
throw IndexOutOfRangeException
Steps to reproduce the Problem (you can add files)
TryEvaluateHashOrArrayLikeObject methods in Context class does not check if the index is a valid key and throws IndexOutOfRangeException.