Skip to content

Commit

Permalink
[Fix] utils.merge`: avoid a crash with a null target and a truthy n…
Browse files Browse the repository at this point in the history
…on-array source
  • Loading branch information
ljharb committed Feb 1, 2019
1 parent ef27de4 commit 49ad67f
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 @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } });
Expand Down

0 comments on commit 49ad67f

Please sign in to comment.