liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Cycle context variables

Open jg-rp opened this issue 2 years ago • 1 comments

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.

jg-rp avatar Feb 14 '22 11:02 jg-rp

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.

dylanahsmith avatar Feb 14 '22 19:02 dylanahsmith