liquid
liquid copied to clipboard
Whitespace flags not respected on blocks (for/if)
Checklist
- [x] I have searched the issue list
- [x] I have tested my example against Shopify Liquid. (This isn't necessary if the actual behavior is a panic, or an error for which
IsTemplateError
returns false.)
Expected Behavior
Respect whitespace flags in for
and if
blocks.
My friends are:
{%- for friend in people -%}
{{ friend }},
{%- endfor -%}
and I like them!
with
{"people": ["alice", "bob"]}
Should render as
My friends are:alice,bob,and I like them!
https://liquidjs.com/playground.html#TXkgZnJpZW5kcyBhcmU6Cgp7JS0gZm9yIGZyaWVuZCBpbiBwZW9wbGUgLSV9Cnt7IGZyaWVuZCB9fSwKeyUtIGVuZGZvciAtJX0KCmFuZCBJIGxpa2UgdGhlbSE=,eyJwZW9wbGUiOiBbImFsaWNlIiwgImJvYiJdfQ==
Actual Behavior
Whitespace flags are ignored:
My friends are:
alice,
bob,
and I like them!
Detailed Description
It seems the TrimLeft and TrimRight functions aren't invoked at the block level.
Possible Solution
Invoke TrimLeft and TrimRight on the block during rendering.
Opening a PR to fix this.
hi, @chrisghill What to Publish a New Version, fix bug
Hey @zsdyx. I'm sorry, I don't understand what you asked.
The proposed pull request does not completely fix the issue as "block" nodes have actually 4 trim params: left outside, right inside, left inside, right outside and in PR it handles only "outside" trims.
That would be great to have all whitespace trim issues fixed some day :)
... and with if/elsif/else it's getting even worse 😨
I also notices the whitespace control does not match normal liquid behavior and opened a PR with an attempt to fix it. Feedback is much appreciated :)