Skip to content

Commit

Permalink
[Fix] utils: merge: fix crash when source is a truthy primitive…
Browse files Browse the repository at this point in the history
… & no options are provided
  • Loading branch information
ljharb committed Sep 17, 2018
1 parent b6956c9 commit d1d1a97
Show file tree
Hide file tree
Showing 2 changed files with 4 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 @@ -54,7 +54,7 @@ var merge = function merge(target, source, options) {
if (Array.isArray(target)) {
target.push(source);
} else if (typeof target === 'object') {
if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
target[source] = true;
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ test('merge()', function (t) {
var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });

var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });

t.end();
});

Expand Down

0 comments on commit d1d1a97

Please sign in to comment.