fix error in transform function when dealing with dropped entries (#287)

This commit is contained in:
Augusto Franzoia 2017-10-31 23:12:31 +02:00 committed by Matt Hamann
parent 9f70ba148f
commit b1ee63cfa4
2 changed files with 36 additions and 4 deletions

View file

@ -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;
}, {});
}

View file

@ -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