diff --git a/index.js b/index.js index 781c883..5e0639a 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,10 @@ const parseString = (() => { context = context || {}; return matches.reduce((str, match, i) => { const parameter = parameters[i]; - const value = objectPath.get(context, parameter.key) || parameter.defaultValue; + let value = objectPath.get(context, parameter.key) + if (value === undefined) { + value = parameter.defaultValue; + } if (typeof value === 'object') { return value; diff --git a/test.js b/test.js index d4d5045..e91e940 100644 --- a/test.js +++ b/test.js @@ -125,6 +125,11 @@ describe('json-template', () => { ); assert.equal(template(), 'http://www.host.com/path?key_1=value'); }); + + it('should handle empty strings for parameter value', () => { + const template = parse('{{foo}}'); + assert.equal(template({ foo: '' }), ''); + }); }); // This section tests that the parse function recursively