Skip to content

Commit 490ff43

Browse files
authored
fix: Allow lenientIf for multiple operands (issue #682) (#683)
* allow `lenientIf` for multiple operands * update tests
1 parent e09657c commit 490ff43

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/render/expression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Expression {
2424
}
2525
operands.push(result)
2626
} else {
27-
operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1))
27+
operands.push(yield evalToken(token, ctx, lenient))
2828
}
2929
}
3030
return operands[0]

test/integration/liquid/strict.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ describe('LiquidOptions#strict*', function () {
5555
const html = await engine.render(tpl, ctx)
5656
return expect(html).toBe('beforeXafter')
5757
})
58-
it('should still throw with an undefined variable in a compound `if` expression', function () {
59-
const tpl = engine.parse('{% if notdefined == 15 %}a{% endif %}')
60-
const fhtml = engine.render(tpl, ctx)
61-
return expect(fhtml).rejects.toThrow(/undefined variable: notdefined/)
58+
it('should not throw with an undefined variable in a compound `if` expression', async function () {
59+
const tpl = engine.parse('before{% if notdefined == 15 %}X{% else %}Y{% endif %}after')
60+
const html = await engine.render(tpl, ctx)
61+
return expect(html).toBe('beforeYafter')
62+
})
63+
it('should correctly evaluate undefined variable in a compound `if` expression', async function () {
64+
const tpl = engine.parse('before{% if notdefined != "value" %}X{% else %}Y{% endif %}after')
65+
const html = await engine.render(tpl, ctx)
66+
return expect(html).toBe('beforeXafter')
6267
})
6368
it('should allow an undefined variable when before the `default` filter', async function () {
6469
const tpl = engine.parse('{{notdefined | default: "a" | tolower}}')

0 commit comments

Comments
 (0)