Ensure _.defaultsDeep does not overwrite regexp values.

This commit is contained in:
John-David Dalton
2016-02-27 14:35:20 -08:00
parent 2e790fb865
commit 63f8b1dcec
2 changed files with 14 additions and 3 deletions

View File

@@ -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;
}
/**

View File

@@ -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);