fix: map filter allow nil results in strict mode, fixes #647

This commit is contained in:
Harttle
2023-08-24 00:20:57 +08:00
parent 942944eae0
commit 45adbd7008
5 changed files with 16 additions and 5 deletions
+8
View File
@@ -58,6 +58,14 @@ describe('filters/array', function () {
const post = { category: 'foo' }
return test('{{post | map: "category"}}', { post }, 'foo')
})
it('should allow nil results in strictVariables mode', function () {
const engine = new Liquid({ strictVariables: true })
const ctx = {
posts: [{ category: 'foo' }, { title: 'bar' }]
}
const result = engine.parseAndRenderSync('{{posts | map: "category" | json}}', ctx)
expect(result).toEqual('["foo",null]')
})
it('should support nested property', function () {
const tpl = '{{ arr | map: "name.first" | join }}'
const a = { name: { first: 'Alice' } }