diff --git a/filters.js b/filters.js index 0ed743611..3ea8e75b8 100644 --- a/filters.js +++ b/filters.js @@ -23,7 +23,7 @@ var filters = { 'ceil': v => Math.ceil(v), 'date': (v, arg) => { if (v === 'now') v = new Date(); - return strftime(v, arg); + return v instanceof Date ? strftime(v, arg) : ''; }, 'default': (v, arg) => v || arg, 'divided_by': (v, arg) => Math.floor(v / arg), diff --git a/test/filters.js b/test/filters.js index 95033fd23..0aef8554b 100644 --- a/test/filters.js +++ b/test/filters.js @@ -51,6 +51,9 @@ describe('filters', function() { it('should create a new Date when given "now"', function() { return test('{{ "now" | date: "%Y"}}', (new Date).getFullYear().toString()); }); + it('should render as empty string when invalid', function() { + return test('{{ "" | date: "%Y"}}', ""); + }); }); describe('default', function() {