bkiers / Liqp

An ANTLR based 'Liquid Template' parser and rendering engine.
MIT License
165 stars 94 forks source link

Invalid scope for variables, defined via "increment" and "decrement" tags #181

Closed msangel closed 3 years ago

msangel commented 3 years ago

In a liquid the variables for "increment" and "decrement" tags are stored separately in context.environments.first hash-object. And the current execution scope stored in context.scopes.last. This cause the variables defined in "increment" and "decrement" live independently and be the same across all execution, no matter the scope. And the variable resolving in context.find_variable method act this way: first it looks thou all scopes and if not found variable there - iterate through all environments.

The behavior is different in this library. It separates the "increment" and "decrement" from anothers by manipulating their name, but the scope visibility is limited to current scope.

Simple test case with error: "{% increment var %}{% assign var=5 %}{% increment var %}{{ var }}{% increment var %}" in liquid gives: 0152 but this library gives 0122