liquid
liquid copied to clipboard
Cycle context variables
Noting that documentation for the cycle
tag only mentions cycling through lists of strings, and existing integration tests cover cycling through lists of integers, is the behaviour demonstrated by the following example considered a bug?
require 'liquid'
template = Liquid::Template.parse(
"{% cycle a, b, c %} {% cycle a, b, c %} {% cycle a, b, c %}")
puts(template.render!({"a" => 1, "b" => 2, "c" => 3}))
Output:
1 1 1
Expected Output:
1 2 3
I can see that the cycle tag was changed with this commit to parse cycle arguments as expressions, rather than treating them as strings. It appears that a string representation of objects returned from parse_expression()
doesn't make a good context key.
Good catch, that was definitely an unintentional behaviour change, where the intention of that commit was only to move the parsing of expression objects to happen during template parsing rather than being repeated each time the tag is rendered.
I'm not sure why that behaviour wasn't covered by tests or noticed in the last 8 years. Unfortunately, we may how have liquid templates that rely on that bug.