mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
fix: escape filter when input is undefined
This commit is contained in:
@@ -14,7 +14,7 @@ const unescapeMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function escape (str: string) {
|
function escape (str: string) {
|
||||||
return String(str).replace(/&|<|>|"|'/g, m => escapeMap[m])
|
return !!str ? String(str).replace(/&|<|>|"|'/g, m => escapeMap[m]) : ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function unescape (str: string) {
|
function unescape (str: string) {
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ describe('filters/html', function () {
|
|||||||
it('should escape function', function () {
|
it('should escape function', function () {
|
||||||
return test('{{ func | escape }}', 'function () { }')
|
return test('{{ func | escape }}', 'function () { }')
|
||||||
})
|
})
|
||||||
|
it('should escape undefined', function () {
|
||||||
|
return test('{{ nonExistent.value | escape }}', '')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
describe('escape_once', function () {
|
describe('escape_once', function () {
|
||||||
it('should do escape', () =>
|
it('should do escape', () =>
|
||||||
|
|||||||
Reference in New Issue
Block a user