liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Allow use of curlies in a properly quoted string

Open knu opened this issue 10 years ago • 8 comments

Currently Liquid does not even allow a closing curly brace to be put inside of a variable, but you sometimes need to deal with the character.

knu avatar Jul 13 '15 06:07 knu

Hm I think we tried to fix this before and we didn't merge it because it negatively impacted performance by quite a bit. @trishume might remember.

fw42 avatar Jul 13 '15 13:07 fw42

Does this bug exist in the strict parser as well?

fw42 avatar Jul 13 '15 13:07 fw42

It's not ideal, but you can work around this with a capture. Using your test case ({{funk | replace: "}", '}}' }}) as an example:

{% capture match %}}{% endcapture %}
{% capture replacement %}}}{% endcapture %}
{{ funk | replace: match, replacement }}
# the above Liquid is in the `text` variable
Liquid::Template.parse(text).render({ 'funk' => '{x}' })
#=> {x}}

nickpearson avatar Jul 13 '15 14:07 nickpearson

See https://github.com/Shopify/liquid/pull/170

I don't think the strict parser would help since this is an issue with the tokenizer, which comes before the strict parser.

It is possible that liquid-c could fix this without a performance hit but that would make it act differently than base liquid.

trishume avatar Jul 13 '15 15:07 trishume

The problem is that we separate the tokenizer and parser, which is necessary for the regex approach but not for the strict approach. I don't think we're at the state where we could merge the two though :(

pushrax avatar Jul 13 '15 16:07 pushrax

We should try implementing this in liquid-c, since performance was the main concern with #170. #170 also seems to have implemented support for \ escaping, but I don't know if that is safe to add without breaking things.

dylanahsmith avatar Jul 13 '15 16:07 dylanahsmith

This is missing integration tests, which are preferred since they get used with liquid-c.

dylanahsmith avatar Jul 14 '15 02:07 dylanahsmith

Thanks for taking a look, guys. I actually didn't know a fix for this had once been rejected due to performance issues, but if there's any kind of benchmark index/threshold Liquid must surpass, I'm willing to improve the implementation.

knu avatar Jul 14 '15 06:07 knu