dotliquid / dotliquid

.NET Port of Tobias Lütke's Liquid template language.
http://dotliquidmarkup.org
Other
1.04k stars 299 forks source link

IndexOutOfRangeException #531

Open davide1993 opened 9 months ago

davide1993 commented 9 months ago

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.

image

microalps commented 9 months 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.

davide1993 commented 9 months ago

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.

microalps commented 1 month ago

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.