Skip to content

Commit

Permalink
fix: proper error message for filter syntax error, #610
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Jun 3, 2023
1 parent 82ba548 commit 0480d33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parser/tokenizer.ts
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/issues.spec.ts
Expand Up @@ -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/)
})
})

0 comments on commit 0480d33

Please sign in to comment.