mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Ensure _.mergeWith overwrites primitives with source object clones. [closes #1880]
This commit is contained in:
@@ -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 {
|
||||
|
||||
10
test/test.js
10
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'] } });
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user