Skip to content

Commit

Permalink
fix: escape filter when input is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
jamelait authored and harttle committed Aug 25, 2019
1 parent 0f4e6d9 commit a00945c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builtin/filters/html.ts
Expand Up @@ -14,7 +14,7 @@ const unescapeMap = {
}

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) {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/builtin/filters/html.ts
Expand Up @@ -12,6 +12,9 @@ describe('filters/html', function () {
it('should escape function', function () {
return test('{{ func | escape }}', 'function () { }')
})
it('should escape undefined', function () {
return test('{{ nonExistent.value | escape }}', '')
})
})
describe('escape_once', function () {
it('should do escape', () =>
Expand Down

0 comments on commit a00945c

Please sign in to comment.