Skip to content

Commit

Permalink
Merge pull request #26 from flovouin/HandleEmptyStrings
Browse files Browse the repository at this point in the history
Handle empty strings
  • Loading branch information
curran authored Nov 1, 2018
2 parents 343783e + 566ea55 commit 83414f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83414f1

Please sign in to comment.