diff --git a/src/builtin/filters/string.ts b/src/builtin/filters/string.ts index b868f3f04..c09208979 100644 --- a/src/builtin/filters/string.ts +++ b/src/builtin/filters/string.ts @@ -6,8 +6,8 @@ import { stringify } from '../../util/underscore' export default { - 'append': (v: string, arg: string) => stringify(v) + arg, - 'prepend': (v: string, arg: string) => arg + stringify(v), + 'append': (v: string, arg: string) => stringify(v) + stringify(arg), + 'prepend': (v: string, arg: string) => stringify(arg) + stringify(v), 'capitalize': capitalize, 'lstrip': (v: string) => stringify(v).replace(/^\s+/, ''), 'downcase': (v: string) => stringify(v).toLowerCase(), diff --git a/test/integration/builtin/filters/string.ts b/test/integration/builtin/filters/string.ts index 2aa423145..2a592caaf 100644 --- a/test/integration/builtin/filters/string.ts +++ b/test/integration/builtin/filters/string.ts @@ -10,7 +10,16 @@ describe('filters/string', function () { describe('append', function () { it('should return "-3abc" for -3, "abc"', () => test('{{ -3 | append: "abc" }}', '-3abc')) - it('should return "abar" for "a",foo', () => test('{{ "a" | append: foo }}', 'abar')) + it('should return "abar" for "a", foo', () => test('{{ "a" | append: foo }}', 'abar')) + it('should return "abc" for "abc", undefined', () => test('{{ "abc" | append: undefinedVar }}', 'abc')) + it('should return "abcfalse" for "abc", false', () => test('{{ "abc" | append: false }}', 'abcfalse')) + }) + describe('prepend', function () { + it('should return "-3abc" for -3, "abc"', + () => test('{{ -3 | prepend: "abc" }}', 'abc-3')) + it('should return "abar" for "a", foo', () => test('{{ "a" | prepend: foo }}', 'bara')) + it('should return "abc" for "abc", undefined', () => test('{{ "abc" | prepend: undefinedVar }}', 'abc')) + it('should return "falseabc" for "abc", false', () => test('{{ "abc" | prepend: false }}', 'falseabc')) }) describe('capitalize', function () { it('should capitalize first', async () => {