liquid
liquid copied to clipboard
Allow use of curlies in a properly quoted string
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.
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.
Does this bug exist in the strict parser as well?
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}}
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.
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 :(
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.
This is missing integration tests, which are preferred since they get used with liquid-c.
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.