Skip to content

Commit

Permalink
fix: throw error on 'else if' tag
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-hamilton committed Feb 14, 2024
1 parent 4518a19 commit 8ef4857
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tokens/tag-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class TagToken extends DelimitedToken {
this.tokenizer = new Tokenizer(input, options.operators, file, this.contentRange)
this.name = this.tokenizer.readTagName()
this.tokenizer.assert(this.name, `illegal tag syntax, tag name expected`)
this.tokenizer.assert(this.name !== 'else' || this.contentRange[1] - this.contentRange[0] === 4, () => `unexpected token: ${this.tokenizer.snapshot()}`)
this.tokenizer.skipBlank()
}
get args (): string {
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/issues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,9 @@ describe('Issues', function () {
const result = engine.parseAndRenderSync('{{ÜLKE}}', { ÜLKE: 'Türkiye' })
expect(result).toEqual('Türkiye')
})
it('#667 should throw if \'else if\' is used instead of \'elsif\'', () => {
const engine = new Liquid()
const tpl = '{% if true %}true{% else if false %}false{% endif %}'
expect(() => engine.parse(tpl)).toThrow('unexpected token: " if false"')
})
})

0 comments on commit 8ef4857

Please sign in to comment.