diff --git a/lib/nconf/common.js b/lib/nconf/common.js index 83c9081..9aa69ee 100644 --- a/lib/nconf/common.js +++ b/lib/nconf/common.js @@ -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; + }, {}); } diff --git a/test/complete-test.js b/test/complete-test.js index 40897de..0245fdf 100644 --- a/test/complete-test.js +++ b/test/complete-test.js @@ -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