Ensure _.merge skips undefined values if a destination value exists.

This commit is contained in:
jdalton
2015-05-18 07:29:35 -07:00
parent 0eba3a3678
commit 882d84f1e6
2 changed files with 18 additions and 1 deletions

View File

@@ -2534,7 +2534,7 @@
if (isCommon) {
result = srcValue;
}
if ((isSrcArr || result !== undefined) &&
if ((result !== undefined || (isSrcArr && !(key in object))) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}

View File

@@ -10681,6 +10681,23 @@
deepEqual(actual, expected);
});
test('should skip `undefined` values in arrays if a destination value exists', 2, function() {
var array = Array(3);
array[0] = 1;
array[2] = 3;
var actual = _.merge([4, 5, 6], array),
expected = [1, 5, 3];
deepEqual(actual, expected);
array = [1, , 3];
array[1] = undefined;
actual = _.merge([4, 5, 6], array);
deepEqual(actual, expected);
});
test('should merge `arguments` objects', 3, function() {
var object1 = { 'value': args },
object2 = { 'value': { '3': 4 } },