Skip to content

Commit c41a5d5

Browse files
committedJul 14, 2022
fix: throw ParseError instead of RenderError for invalid assign expression, closes #519
1 parent 0aca2dd commit c41a5d5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed
 

‎src/builtin/tags/assign.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tokenizer, assert, TagImplOptions, TagToken, Context } from '../../types'
1+
import { Value, Tokenizer, assert, TagImplOptions, TagToken, Context } from '../../types'
22

33
export default {
44
parse: function (token: TagToken) {
@@ -7,9 +7,9 @@ export default {
77
tokenizer.skipBlank()
88
assert(tokenizer.peek() === '=', () => `illegal token ${token.getText()}`)
99
tokenizer.advance()
10-
this.value = tokenizer.remaining()
10+
this.value = new Value(tokenizer.remaining(), this.liquid)
1111
},
1212
render: function * (ctx: Context): Generator<unknown, void, unknown> {
13-
ctx.bottom()[this.key] = yield this.liquid._evalValue(this.value, ctx)
13+
ctx.bottom()[this.key] = yield this.value.value(ctx, this.liquid.options.lenientIf)
1414
}
1515
} as TagImplOptions

‎test/e2e/issues.ts

+4
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,8 @@ describe('Issues', function () {
256256
const html = engine.parseAndRenderSync(`{% for i in (1..10000) %}{{ i }}{% endfor %}`)
257257
expect(html).to.have.lengthOf(38894)
258258
})
259+
it('#519 should throw parse error for invalid assign expression', () => {
260+
const engine = new Liquid()
261+
expect(() => engine.parse('{% assign headshot = https://testurl.com/not_enclosed_in_quotes.jpg %}')).to.throw(/unexpected token at ":/)
262+
})
259263
})

‎test/integration/builtin/tags/assign.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Liquid } from '../../../../src/liquid'
1+
import { ParseError, Liquid } from '../../../../src/liquid'
22
import { expect, use } from 'chai'
33
import * as chaiAsPromised from 'chai-as-promised'
44

@@ -16,9 +16,10 @@ describe('tags/assign', function () {
1616
const html = await liquid.parseAndRender(src)
1717
return expect(html).to.equal('bar')
1818
})
19-
it('should throw when variable value illegal', async function () {
19+
it('should throw when variable value illegal', function () {
2020
const src = '{% assign foo = “bar” %}'
21-
return expect(liquid.parseAndRender(src)).to.be.rejectedWith(/unexpected token at "bar"/)
21+
expect(() => liquid.parse(src)).to.throw(/unexpected token at "bar"/)
22+
expect(() => liquid.parse(src)).to.throw(ParseError)
2223
})
2324
it('should support assign to a number', async function () {
2425
const src = '{% assign foo=10086 %}{{foo}}'

0 commit comments

Comments
 (0)
Please sign in to comment.