Skip to content

Commit

Permalink
fix error in transform function when dealing with dropped entries (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfranzoia authored and mhamann committed Oct 31, 2017
1 parent 9f70ba1 commit b1ee63c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/nconf/common.js
Expand Up @@ -164,8 +164,12 @@ common.transform = function(map, fn) {
});


return pairs.reduce(function(accumulator, pair) {
accumulator[pair.key] = pair.value;
return accumulator;
}, {});
return pairs
.filter(function(pair) {
return pair !== null;
})
.reduce(function(accumulator, pair) {
accumulator[pair.key] = pair.value;
return accumulator;
}, {});
}
28 changes: 28 additions & 0 deletions test/complete-test.js
Expand Up @@ -214,6 +214,34 @@ vows.describe('nconf/multiple-stores').addBatch({
teardown: function () {
nconf.remove('env');
}
}).addBatch({
// Threw this in it's own batch to make sure it's run separately from the
// sync check
"When using env with a transform:fn that drops an entry": {
topic: function () {

function testTransform(obj) {
if (obj.key === 'FOO') {
return false;
}

return obj;
}

var that = this;
helpers.cp(complete, completeTest, function () {
nconf.env({ transform: testTransform });
that.callback();
});
}, "env vars": {
"port key/value properly transformed": function() {
assert.equal(typeof nconf.get('FOO'), 'undefined');
}
}
},
teardown: function () {
nconf.remove('env');
}
}).addBatch({
// Threw this in it's own batch to make sure it's run separately from the
// sync check
Expand Down

0 comments on commit b1ee63c

Please sign in to comment.