fix: corner case for concat filter without argument, #481

This commit is contained in:
Harttle
2022-03-02 21:21:25 +08:00
parent 15b78ebd9d
commit aa955173d4
5 changed files with 70 additions and 4 deletions
+7 -1
View File
@@ -217,8 +217,14 @@ describe('Issues', function () {
{{ foo | newline_to_br }}
{{ foo | strip_html }}
{{ foo | truncatewords }}
{{ foo | concat | json }}
`)
const html = await engine.render(tpl, { foo: undefined })
expect(html.trim()).to.equal('')
expect(html.trim()).to.equal('[]')
})
it('#481 concat should always return an array', async () => {
const engine = new Liquid()
const html = await engine.parseAndRender(`{{ foo | concat | json }}`)
expect(html).to.equal('[]')
})
})
+13
View File
@@ -75,11 +75,24 @@ describe('filters/array', function () {
})
describe('concat', () => {
it('should concat args value', async () => {
const scope = { val: ['hey'], arr: ['foo', 'bar'] }
await test('{{ val | concat: arr | join: "," }}', scope, 'hey,foo,bar')
})
it('should support undefined left value', async () => {
const scope = { arr: ['foo', 'bar'] }
await test('{{ notDefined | concat: arr | join: "," }}', scope, 'foo,bar')
})
it('should ignore nil left value', async () => {
const scope = { undefinedValue: undefined, nullValue: null, arr: ['foo', 'bar'] }
await test('{{ undefinedValue | concat: arr | join: "," }}', scope, 'foo,bar')
await test('{{ nullValue | concat: arr | join: "," }}', scope, 'foo,bar')
})
it('should ignore nil right value', async () => {
const scope = { nullValue: null }
await test('{{ nullValue | concat | join: "," }}', scope, '')
await test('{{ nullValue | concat: nil | join: "," }}', scope, '')
})
})
describe('reverse', function () {