From 6cf5f81b6c312f90f57d34b6e5c390c5cdebd43a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 17 Sep 2018 16:16:06 -0700 Subject: [PATCH] [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided --- lib/utils.js | 2 +- test/utils.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index b2143323..e0ebba2d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 { diff --git a/test/utils.js b/test/utils.js index 0721dd8e..999f860d 100644 --- a/test/utils.js +++ b/test/utils.js @@ -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(); });