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 c38b943 commit 471261a
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
Expand Up @@ -31,7 +31,7 @@ exports.merge = function (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
Expand Up @@ -18,5 +18,8 @@ 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();
});

0 comments on commit 471261a

Please sign in to comment.