diff --git a/lodash.js b/lodash.js index e85087be6..c5a286afe 100644 --- a/lodash.js +++ b/lodash.js @@ -3057,7 +3057,7 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { var objValue = object[key], srcValue = source[key], - stacked = stack.get(srcValue) || stack.get(objValue); + stacked = stack.get(srcValue); if (stacked) { assignMergeValue(object, key, stacked); @@ -3076,6 +3076,7 @@ newValue = copyArray(objValue); } else { + isCommon = false; newValue = baseClone(srcValue); } } @@ -3084,6 +3085,7 @@ newValue = toPlainObject(objValue); } else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { + isCommon = false; newValue = baseClone(srcValue); } else { diff --git a/test/test.js b/test/test.js index 3de3a36d3..228e7bba1 100644 --- a/test/test.js +++ b/test/test.js @@ -13528,6 +13528,16 @@ assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } }); }); + + QUnit.test('should overwrite primitives with source object clones', function(assert) { + assert.expect(1); + + var actual = _.mergeWith({ 'a': 0 }, { 'a': { 'b': ['c'] } }, function(a, b) { + return lodashStable.isArray(a) ? a.concat(b) : undefined; + }); + + assert.deepEqual(actual, { 'a': { 'b': ['c'] } }); + }); }()); /*--------------------------------------------------------------------------*/