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 = (
8888 const regex = new RegExp ( pattern , 'gmi' ) ;
8989 if ( regex . test ( templatePortion ) ) matched = data [ prop ] ;
9090 }
91- return matched || templatePortion ;
91+ if ( typeof matched === 'undefined' ) return templatePortion ;
92+ return matched ;
9293 } ) ;
9394
9495 // 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', () => {
9090 const after = [ 'Hello this is a ' , < Comp /> , ' translation' ] ;
9191 const result = utils . templater ( before , data ) ;
9292 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+ } ) ;
94102 } ) ;
95103
96104 describe ( 'getIndexForLanguageCode' , ( ) => {
You can’t perform that action at this time.
0 commit comments