File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,8 @@ export const templater = (
88
88
const regex = new RegExp ( pattern , 'gmi' ) ;
89
89
if ( regex . test ( templatePortion ) ) matched = data [ prop ] ;
90
90
}
91
- return matched || templatePortion ;
91
+ if ( typeof matched === 'undefined' ) return templatePortion ;
92
+ return matched ;
92
93
} ) ;
93
94
94
95
// if there is a React element, return as array
Original file line number Diff line number Diff line change @@ -90,7 +90,15 @@ describe('locale utils', () => {
90
90
const after = [ 'Hello this is a ' , < Comp /> , ' translation' ] ;
91
91
const result = utils . templater ( before , data ) ;
92
92
expect ( result ) . toEqual ( after ) ;
93
- } )
93
+ } ) ;
94
+
95
+ it ( 'should handle falsy data values (except undefined)' , ( ) => {
96
+ const data = { zero : 0 , empty : '' } ;
97
+ const before = 'Number ${zero}, empty ${empty}' ;
98
+ const after = 'Number 0, empty ' ;
99
+ const result = utils . templater ( before , data ) ;
100
+ expect ( result ) . toEqual ( after ) ;
101
+ } ) ;
94
102
} ) ;
95
103
96
104
describe ( 'getIndexForLanguageCode' , ( ) => {
You can’t perform that action at this time.
0 commit comments