diff --git a/lodash.js b/lodash.js index af94b50a0..22f9ec2c7 100644 --- a/lodash.js +++ b/lodash.js @@ -4841,7 +4841,7 @@ * @returns {*} Returns the value to assign to the destination object. */ function mergeDefaults(objValue, srcValue, key, object, source, stack) { - if (isObject(objValue)) { + if (isObject(objValue) && isObject(srcValue)) { stack.set(srcValue, objValue); baseMerge(objValue, srcValue, mergeDefaults, stack); } diff --git a/test/test.js b/test/test.js index b654dfd49..1d423f3c4 100644 --- a/test/test.js +++ b/test/test.js @@ -3658,15 +3658,21 @@ QUnit.test('should not modify sources', function(assert) { assert.expect(3); - var object = {}, - source1 = { 'a': 1, 'b': { 'c': 2 } }, + var source1 = { 'a': 1, 'b': { 'c': 2 } }, source2 = { 'b': { 'c': 3, 'd': 3 } }, - actual = _.defaultsDeep(object, source1, source2); + actual = _.defaultsDeep({}, source1, source2); assert.deepEqual(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } }); assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } }); assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } }); }); + + QUnit.test('should not attempt a merge of a string into an array', function(assert) { + assert.expect(1); + + var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' }); + assert.deepEqual(actual, { 'a': ['abc'] }); + }); }()); /*--------------------------------------------------------------------------*/