Skip to content

Commit

Permalink
[Fix] utils.merge: avoid a crash with a null target and an array so…
Browse files Browse the repository at this point in the history
…urce
  • Loading branch information
ljharb committed Feb 3, 2019
1 parent d856d80 commit a54ca9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.merge = function (target, source, options) {
return target;
}

if (typeof target !== 'object') {
if (!target || typeof target !== 'object') {
return [target].concat(source);
}

Expand Down
2 changes: 2 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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(null, [42]), [null, 42], 'merges null into an array');

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' } });
Expand Down

0 comments on commit a54ca9e

Please sign in to comment.