File tree 2 files changed +14
-3
lines changed
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -989,11 +989,14 @@ lib.templateString = function(string, obj) {
989
989
var getterCache = { } ;
990
990
991
991
return string . replace ( lib . TEMPLATE_STRING_REGEX , function ( dummy , key ) {
992
+ var v ;
992
993
if ( SIMPLE_PROPERTY_REGEX . test ( key ) ) {
993
- return obj [ key ] || '' ;
994
+ v = obj [ key ] ;
995
+ } else {
996
+ getterCache [ key ] = getterCache [ key ] || lib . nestedProperty ( obj , key ) . get ;
997
+ v = getterCache [ key ] ( ) ;
994
998
}
995
- getterCache [ key ] = getterCache [ key ] || lib . nestedProperty ( obj , key ) . get ;
996
- return getterCache [ key ] ( ) || '' ;
999
+ return lib . isValidTextValue ( v ) ? v : '' ;
997
1000
} ) ;
998
1001
} ;
999
1002
Original file line number Diff line number Diff line change @@ -2229,6 +2229,14 @@ describe('Test lib.js:', function() {
2229
2229
it ( 'replaces empty key with empty string' , function ( ) {
2230
2230
expect ( Lib . templateString ( 'foo %{} %{}' , { } ) ) . toEqual ( 'foo ' ) ;
2231
2231
} ) ;
2232
+
2233
+ it ( 'should work with the number *0*' , function ( ) {
2234
+ expect ( Lib . templateString ( '%{group}' , { group : 0 } ) ) . toEqual ( '0' ) ;
2235
+ } ) ;
2236
+
2237
+ it ( 'should work with the number *0* (nested case)' , function ( ) {
2238
+ expect ( Lib . templateString ( '%{x.y}' , { 'x' : { y : 0 } } ) ) . toEqual ( '0' ) ;
2239
+ } ) ;
2232
2240
} ) ;
2233
2241
2234
2242
describe ( 'hovertemplateString' , function ( ) {
You can’t perform that action at this time.
0 commit comments