Skip to content

Commit a00945c

Browse files
jamelaitharttle
jamelait
authored andcommitted
fix: escape filter when input is undefined
1 parent 0f4e6d9 commit a00945c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/builtin/filters/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const unescapeMap = {
1414
}
1515

1616
function escape (str: string) {
17-
return String(str).replace(/&|<|>|"|'/g, m => escapeMap[m])
17+
return !!str ? String(str).replace(/&|<|>|"|'/g, m => escapeMap[m]) : ""
1818
}
1919

2020
function unescape (str: string) {

test/integration/builtin/filters/html.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ describe('filters/html', function () {
1212
it('should escape function', function () {
1313
return test('{{ func | escape }}', 'function () { }')
1414
})
15+
it('should escape undefined', function () {
16+
return test('{{ nonExistent.value | escape }}', '')
17+
})
1518
})
1619
describe('escape_once', function () {
1720
it('should do escape', () =>

0 commit comments

Comments
 (0)