fix: url_encode throws on undefined value, fixes #479

This commit is contained in:
Harttle
2022-02-24 01:14:46 +08:00
parent 2b0c5696bc
commit ca3240c2c4
2 changed files with 12 additions and 2 deletions
+4 -2
View File
@@ -1,2 +1,4 @@
export const urlDecode = (x: string) => x.split('+').map(decodeURIComponent).join(' ')
export const urlEncode = (x: string) => x.split(' ').map(encodeURIComponent).join('+')
import { stringify } from '../../util/underscore'
export const urlDecode = (x: string) => stringify(x).split('+').map(decodeURIComponent).join(' ')
export const urlEncode = (x: string) => stringify(x).split(' ').map(encodeURIComponent).join('+')
+8
View File
@@ -199,4 +199,12 @@ describe('Issues', function () {
const html = engine.parseAndRenderSync('{{foo | size}}-{{bar.coo}}', { foo: 'foo', bar: Object.create({ coo: 'COO' }) })
expect(html).to.equal('3-')
})
it('#479 url_encode throws on undefined value', async () => {
const engine = new Liquid({
strictVariables: false
})
const tpl = engine.parse('{{ v | url_encode }}')
const html = await engine.render(tpl, { v: undefined })
expect(html).to.equal('')
})
})