Ensure _.assign and _.merge don't assign the customizer result if it is the same as the destination value.

This commit is contained in:
John-David Dalton
2014-12-27 19:42:10 -06:00
parent 7f823fe2a8
commit fa2058ec77
2 changed files with 35 additions and 9 deletions

View File

@@ -1691,9 +1691,15 @@
while (++index < length) {
var key = props[index];
object[key] = customizer
? customizer(object[key], source[key], key, object, source)
: source[key];
if (customizer) {
var value = object[key],
result = customizer(value, source[key], key, object, source);
} else {
result = source[key];
}
if (!(customizer && result === value)) {
object[key] = result;
}
}
return object;
}
@@ -2487,7 +2493,7 @@
if (typeof result == 'undefined') {
result = srcValue;
}
if (isSrcArr || typeof result != 'undefined') {
if ((isSrcArr || typeof result != 'undefined') && !(customizer && result === value)) {
object[key] = result;
}
return;
@@ -2520,7 +2526,9 @@
if (isDeep) {
baseMerge(result, srcValue, customizer, stackA, stackB);
}
object[key] = result;
if (!(customizer && result === value)) {
object[key] = result;
}
});
return object;
}