fix: allow quoted variable name in capture, fixes #252

This commit is contained in:
harttle
2020-10-03 22:03:17 +08:00
parent 236d971705
commit 5b3f4195f0
3 changed files with 23 additions and 1 deletions
+8
View File
@@ -10,4 +10,12 @@ describe('Issues', function () {
const html = engine.parseAndRenderSync('{{huh | truncate: 11}}', { huh: 'fdsafdsafdsafdsaaaaa' })
expect(html).to.equal('fdsafdsa...')
})
it('#252 "Not valid identifier" error for a quotes-containing identifier', async () => {
const template = `{% capture "form_classes" -%}
foo
{%- endcapture %}{{form_classes}}`
const engine = new Liquid()
const html = await engine.parseAndRender(template)
expect(html).to.equal('foo')
})
})
+6
View File
@@ -13,6 +13,12 @@ describe('tags/capture', function () {
return expect(html).to.equal('A')
})
it('should support quoted variable name', async function () {
const src = '{% capture "f" %}{{"a" | capitalize}}{%endcapture%}{{f}}'
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('A')
})
it('should shading rather than overwriting', async function () {
const src = '{% capture var %}10{% endcapture %}{{var}}'
const ctx = { 'var': 20 }