mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +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) {
|
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
|
||||||
var objValue = object[key],
|
var objValue = object[key],
|
||||||
srcValue = source[key],
|
srcValue = source[key],
|
||||||
stacked = stack.get(srcValue) || stack.get(objValue);
|
stacked = stack.get(srcValue);
|
||||||
|
|
||||||
if (stacked) {
|
if (stacked) {
|
||||||
assignMergeValue(object, key, stacked);
|
assignMergeValue(object, key, stacked);
|
||||||
@@ -3076,6 +3076,7 @@
|
|||||||
newValue = copyArray(objValue);
|
newValue = copyArray(objValue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
isCommon = false;
|
||||||
newValue = baseClone(srcValue);
|
newValue = baseClone(srcValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3084,6 +3085,7 @@
|
|||||||
newValue = toPlainObject(objValue);
|
newValue = toPlainObject(objValue);
|
||||||
}
|
}
|
||||||
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
|
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
|
||||||
|
isCommon = false;
|
||||||
newValue = baseClone(srcValue);
|
newValue = baseClone(srcValue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
10
test/test.js
10
test/test.js
@@ -13528,6 +13528,16 @@
|
|||||||
|
|
||||||
assert.deepEqual(actual, { 'a': { 'b': [0, 1, 2] } });
|
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