Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow lenientIf for multiple operands (issue #682) #683

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/render/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Expression {
}
operands.push(result)
} else {
operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1))
operands.push(yield evalToken(token, ctx, lenient))
}
}
return operands[0]
Expand Down
13 changes: 9 additions & 4 deletions test/integration/liquid/strict.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ describe('LiquidOptions#strict*', function () {
const html = await engine.render(tpl, ctx)
return expect(html).toBe('beforeXafter')
})
it('should still throw with an undefined variable in a compound `if` expression', function () {
const tpl = engine.parse('{% if notdefined == 15 %}a{% endif %}')
const fhtml = engine.render(tpl, ctx)
return expect(fhtml).rejects.toThrow(/undefined variable: notdefined/)
it('should not throw with an undefined variable in a compound `if` expression', async function () {
const tpl = engine.parse('before{% if notdefined == 15 %}X{% else %}Y{% endif %}after')
const html = await engine.render(tpl, ctx)
return expect(html).toBe('beforeYafter')
})
it('should correctly evaluate undefined variable in a compound `if` expression', async function () {
const tpl = engine.parse('before{% if notdefined != "value" %}X{% else %}Y{% endif %}after')
const html = await engine.render(tpl, ctx)
return expect(html).toBe('beforeXafter')
})
it('should allow an undefined variable when before the `default` filter', async function () {
const tpl = engine.parse('{{notdefined | default: "a" | tolower}}')
Expand Down