liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Deprecate variableLookups on LHS of assign.

Open charlespwd opened this issue 3 years ago • 0 comments

This is obscure and we do support it but behaves rather strangely. We should deprecate this.

{% assign product.img = "hi" %}

{% # prints nothing %}
{{ product.img }}

{% # prints "hi" %}
{{ ["product.img"] }}

It's because we parse the entire assign LHS as a string and then assign the context's <stringValueOfLHS> to be the value of the RHS. And our VariableSegment regex accepts dots and square brackets.

https://github.com/Shopify/liquid/blob/81f44e36be5f2110c26b6532fd4ccd22edaf59f2/lib/liquid/tags/assign.rb#L38

https://github.com/Shopify/liquid/blob/81f44e36be5f2110c26b6532fd4ccd22edaf59f2/lib/liquid/tags/assign.rb#L17

https://github.com/Shopify/liquid/blob/81f44e36be5f2110c26b6532fd4ccd22edaf59f2/lib/liquid.rb#L33

While we're there, we should probably cleanup our regex for variable segment, variable signature, etc.

charlespwd avatar Aug 09 '22 18:08 charlespwd