mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Ensure _.merge skips undefined values if a destination value exists.
This commit is contained in:
@@ -2534,7 +2534,7 @@
|
|||||||
if (isCommon) {
|
if (isCommon) {
|
||||||
result = srcValue;
|
result = srcValue;
|
||||||
}
|
}
|
||||||
if ((isSrcArr || result !== undefined) &&
|
if ((result !== undefined || (isSrcArr && !(key in object))) &&
|
||||||
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
||||||
object[key] = result;
|
object[key] = result;
|
||||||
}
|
}
|
||||||
|
|||||||
17
test/test.js
17
test/test.js
@@ -10681,6 +10681,23 @@
|
|||||||
deepEqual(actual, expected);
|
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() {
|
test('should merge `arguments` objects', 3, function() {
|
||||||
var object1 = { 'value': args },
|
var object1 = { 'value': args },
|
||||||
object2 = { 'value': { '3': 4 } },
|
object2 = { 'value': { '3': 4 } },
|
||||||
|
|||||||
Reference in New Issue
Block a user