diff --git a/src/builtin/tags/assign.ts b/src/builtin/tags/assign.ts index 9902f1f62a..8891105137 100644 --- a/src/builtin/tags/assign.ts +++ b/src/builtin/tags/assign.ts @@ -1,4 +1,4 @@ -import { Tokenizer, assert, TagImplOptions, TagToken, Context } from '../../types' +import { Value, Tokenizer, assert, TagImplOptions, TagToken, Context } from '../../types' export default { parse: function (token: TagToken) { @@ -7,9 +7,9 @@ export default { tokenizer.skipBlank() assert(tokenizer.peek() === '=', () => `illegal token ${token.getText()}`) tokenizer.advance() - this.value = tokenizer.remaining() + this.value = new Value(tokenizer.remaining(), this.liquid) }, render: function * (ctx: Context): Generator { - ctx.bottom()[this.key] = yield this.liquid._evalValue(this.value, ctx) + ctx.bottom()[this.key] = yield this.value.value(ctx, this.liquid.options.lenientIf) } } as TagImplOptions diff --git a/test/e2e/issues.ts b/test/e2e/issues.ts index 72570be4f1..f81a7be792 100644 --- a/test/e2e/issues.ts +++ b/test/e2e/issues.ts @@ -256,4 +256,8 @@ describe('Issues', function () { const html = engine.parseAndRenderSync(`{% for i in (1..10000) %}{{ i }}{% endfor %}`) expect(html).to.have.lengthOf(38894) }) + it('#519 should throw parse error for invalid assign expression', () => { + const engine = new Liquid() + expect(() => engine.parse('{% assign headshot = https://testurl.com/not_enclosed_in_quotes.jpg %}')).to.throw(/unexpected token at ":/) + }) }) diff --git a/test/integration/builtin/tags/assign.ts b/test/integration/builtin/tags/assign.ts index 5f08b99991..201562a42d 100644 --- a/test/integration/builtin/tags/assign.ts +++ b/test/integration/builtin/tags/assign.ts @@ -1,4 +1,4 @@ -import { Liquid } from '../../../../src/liquid' +import { ParseError, Liquid } from '../../../../src/liquid' import { expect, use } from 'chai' import * as chaiAsPromised from 'chai-as-promised' @@ -16,9 +16,10 @@ describe('tags/assign', function () { const html = await liquid.parseAndRender(src) return expect(html).to.equal('bar') }) - it('should throw when variable value illegal', async function () { + it('should throw when variable value illegal', function () { const src = '{% assign foo = “bar” %}' - return expect(liquid.parseAndRender(src)).to.be.rejectedWith(/unexpected token at "“bar”"/) + expect(() => liquid.parse(src)).to.throw(/unexpected token at "“bar”"/) + expect(() => liquid.parse(src)).to.throw(ParseError) }) it('should support assign to a number', async function () { const src = '{% assign foo=10086 %}{{foo}}'