Skip to content

Commit

Permalink
fix: capitalize filter not lower case trailing string, fixes #326
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Apr 17, 2021
1 parent 8bab795 commit 6548765
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/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function stripNewlines (v: string) {

export function capitalize (str: string) {
str = stringify(str)
return str.charAt(0).toUpperCase() + str.slice(1)
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
}

export function replace (v: string, pattern: string, replacement: string) {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/builtin/filters/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ describe('filters/string', function () {
it('should capitalize first', () => test('{{ "i am good" | capitalize }}', 'I am good'))
it('should return empty for nil', () => test('{{ nil | capitalize }}', ''))
it('should return empty for undefined', async () => test('{{ foo | capitalize }}', ''))
it('should capitalize only first word', async () => test('{{"foo bar" | capitalize}}', 'Foo bar'))
it('should to lower case if prefixed by spaces', async () => test('{{" foo BaR" | capitalize}}', ' foo bar'))
it('should to lower case trailing words', async () => test('{{"foo BaR" | capitalize}}', 'Foo bar'))
})
describe('concat', function () {
it('should concat arrays', () => test(`
Expand Down

0 comments on commit 6548765

Please sign in to comment.