diff --git a/src/builtin/filters/object.ts b/src/builtin/filters/object.ts index c8d86abfc4..4aa6c8ec15 100644 --- a/src/builtin/filters/object.ts +++ b/src/builtin/filters/object.ts @@ -1,5 +1,5 @@ -import { isTruthy } from '../../render/syntax' +import { isFalsy } from '../../render/syntax' export default { - 'default': (v: T1, arg: T2): T1 | T2 => isTruthy(v) ? v : arg + 'default': (v: string | T1, arg: T2): string | T1 | T2 => isFalsy(v) || v === '' ? arg : v } diff --git a/test/integration/builtin/filters/object.ts b/test/integration/builtin/filters/object.ts index a135e4b822..78f97e59f4 100644 --- a/test/integration/builtin/filters/object.ts +++ b/test/integration/builtin/filters/object.ts @@ -2,7 +2,12 @@ import { test } from '../../../stub/render' describe('filters/object', function () { describe('default', function () { - it('should use default when falsy', () => test('{{false |default: "a"}}', 'a')) - it('should not use default when truthy', () => test('{{true |default: "a"}}', 'true')) + it('false should use default', () => test('{{false | default: "a"}}', 'a')) + it('empty string should use default', () => test('{{"" | default: "a"}}', 'a')) + it('non-empty string should not use default', () => test('{{" " | default: "a"}}', ' ')) + it('nil should use default', () => test('{{nil | default: "a"}}', 'a')) + it('undefined should use default', () => test('{{not_defined | default: "a"}}', 'a')) + it('true should not use default', () => test('{{true | default: "a"}}', 'true')) + it('0 should not use default', () => test('{{0 | default: "a"}}', '0')) }) })