diff --git a/src/parser/tokenizer.ts b/src/parser/tokenizer.ts index 3c15fe1dc..45183a081 100644 --- a/src/parser/tokenizer.ts +++ b/src/parser/tokenizer.ts @@ -57,7 +57,7 @@ export class Tokenizer { readFilter (): FilterToken | null { this.skipBlank() if (this.end()) return null - assert(this.peek() === '|', () => `unexpected token at ${this.snapshot()}`) + assert(this.peek() === '|', () => `expected "|" before filter`) this.p++ const begin = this.p const name = this.readIdentifier() @@ -72,6 +72,10 @@ export class Tokenizer { this.skipBlank() assert(this.end() || this.peek() === ',' || this.peek() === '|', () => `unexpected character ${this.snapshot()}`) } while (this.peek() === ',') + } else if (this.peek() === '|' || this.end()) { + // do nothing + } else { + throw new Error('expected ":" after filter name') } return new FilterToken(name.getText(), args, this.input, begin, this.p, this.file) } diff --git a/test/e2e/issues.spec.ts b/test/e2e/issues.spec.ts index 09c026482..b4de1f1ed 100644 --- a/test/e2e/issues.spec.ts +++ b/test/e2e/issues.spec.ts @@ -426,4 +426,9 @@ describe('Issues', function () { '2023-01-05T12:00:00+0000' expect(html).toEqual(expected) }) + it('#610 should throw missing ":" after filter name', () => { + const engine = new Liquid() + const fn = () => engine.parseAndRenderSync("{%- assign module = '' | split '' -%}") + expect(fn).toThrow(/expected ":" after filter name/) + }) })