From b95d1d6123beedea643a0727753cde21be5425dc Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 15 Mar 2016 08:32:23 -0700 Subject: [PATCH] Ensure `_.mergeWith` sources are cloned when `customizer` returns `undefiend`. [closes #2111] --- lodash.js | 4 ++-- test/test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index 05ecebe65..ae6941c22 100644 --- a/lodash.js +++ b/lodash.js @@ -3219,7 +3219,7 @@ } else { isCommon = false; - newValue = baseClone(srcValue, !customizer); + newValue = baseClone(srcValue, true); } } else if (isPlainObject(srcValue) || isArguments(srcValue)) { @@ -3228,7 +3228,7 @@ } else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { isCommon = false; - newValue = baseClone(srcValue, !customizer); + newValue = baseClone(srcValue, true); } else { newValue = objValue; diff --git a/test/test.js b/test/test.js index f944db41c..776771810 100644 --- a/test/test.js +++ b/test/test.js @@ -14610,6 +14610,16 @@ assert.deepEqual(actual, { 'a': { 'b': ['c'] } }); }); + QUnit.test('should clone sources when `customizer` result is `undefined`', function(assert) { + assert.expect(1); + + var source1 = { 'a': { 'b': { 'c': 1 } } }, + source2 = { 'a': { 'b': { 'd': 2 } } }, + actual = _.mergeWith({}, source1, source2, alwaysUndefined); + + assert.deepEqual(source1.a.b, { 'c': 1 }); + }); + QUnit.test('should pop the stack of sources for each sibling property', function(assert) { assert.expect(1);