From 882d84f1e66776695eed4e784bb8a66507912f5f Mon Sep 17 00:00:00 2001 From: jdalton Date: Mon, 18 May 2015 07:29:35 -0700 Subject: [PATCH] Ensure `_.merge` skips `undefined` values if a destination value exists. --- lodash.src.js | 2 +- test/test.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lodash.src.js b/lodash.src.js index b806d9bd3..5ef870596 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -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; } diff --git a/test/test.js b/test/test.js index 94a8bf40b..f48e03240 100644 --- a/test/test.js +++ b/test/test.js @@ -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 } },