Skip to content

Commit c7dd66a

Browse files
committed
allow *0* is valid template string value
1 parent 8122c21 commit c7dd66a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/lib/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,14 @@ lib.templateString = function(string, obj) {
989989
var getterCache = {};
990990

991991
return string.replace(lib.TEMPLATE_STRING_REGEX, function(dummy, key) {
992+
var v;
992993
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]();
994998
}
995-
getterCache[key] = getterCache[key] || lib.nestedProperty(obj, key).get;
996-
return getterCache[key]() || '';
999+
return lib.isValidTextValue(v) ? v : '';
9971000
});
9981001
};
9991002

test/jasmine/tests/lib_test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,14 @@ describe('Test lib.js:', function() {
22292229
it('replaces empty key with empty string', function() {
22302230
expect(Lib.templateString('foo %{} %{}', {})).toEqual('foo ');
22312231
});
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+
});
22322240
});
22332241

22342242
describe('hovertemplateString', function() {

0 commit comments

Comments
 (0)