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 915517c commit 213d513
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 @@ -30,7 +30,7 @@ exports.merge = function (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 213d513

Please sign in to comment.