diff --git a/lib/utils.js b/lib/utils.js index 5958edc8..cfed4ecd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -53,7 +53,7 @@ var merge = function merge(target, source, options) { if (typeof source !== 'object') { if (Array.isArray(target)) { target.push(source); - } else if (typeof target === 'object') { + } else if (target && typeof target === 'object') { if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) { target[source] = true; } diff --git a/test/utils.js b/test/utils.js index f255de3f..fcd85a01 100644 --- a/test/utils.js +++ b/test/utils.js @@ -4,6 +4,8 @@ var test = require('tape'); var utils = require('../lib/utils'); test('merge()', function (t) { + t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null'); + t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key'); var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });