Skip to content

Commit 213d513

Browse files
committed
[Fix] utils.merge`: avoid a crash with a null target and a truthy non-array source
1 parent 915517c commit 213d513

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.merge = function (target, source, options) {
3030
if (typeof source !== 'object') {
3131
if (Array.isArray(target)) {
3232
target.push(source);
33-
} else if (typeof target === 'object') {
33+
} else if (target && typeof target === 'object') {
3434
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
3535
target[source] = true;
3636
}

test/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var test = require('tape');
44
var utils = require('../lib/utils');
55

66
test('merge()', function (t) {
7+
t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
8+
79
t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
810

911
var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });

0 commit comments

Comments
 (0)