From 63f8b1dcec9d9bd5d223bc51fb919e32484a5d34 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 27 Feb 2016 14:35:20 -0800 Subject: [PATCH] Ensure `_.defaultsDeep` does not overwrite regexp values. --- lodash.js | 7 ++++--- test/test.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lodash.js b/lodash.js index ffdc66ac8..8e86d2f89 100644 --- a/lodash.js +++ b/lodash.js @@ -5374,9 +5374,10 @@ * @returns {*} Returns the value to assign. */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { - return (isObject(objValue) && isObject(srcValue)) - ? baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue)) - : objValue; + if (isObject(objValue) && isObject(srcValue)) { + baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue)); + } + return objValue; } /** diff --git a/test/test.js b/test/test.js index efb6c24c7..231dcce06 100644 --- a/test/test.js +++ b/test/test.js @@ -4350,6 +4350,16 @@ assert.strictEqual(actual.a.b, null); }); + QUnit.test('should not overwrite regexp values', function(assert) { + assert.expect(1); + + var object = { 'a': { 'b': /x/ } }, + source = { 'a': { 'b': /y/ } }, + actual = _.defaultsDeep(object, source); + + assert.deepEqual(actual.a.b, /x/); + }); + QUnit.test('should not convert function properties to objects', function(assert) { assert.expect(2);