mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Ensure _.defaultsDeep doesn't attempt a merge of a string into an array. [closes #1560]
This commit is contained in:
@@ -4841,7 +4841,7 @@
|
|||||||
* @returns {*} Returns the value to assign to the destination object.
|
* @returns {*} Returns the value to assign to the destination object.
|
||||||
*/
|
*/
|
||||||
function mergeDefaults(objValue, srcValue, key, object, source, stack) {
|
function mergeDefaults(objValue, srcValue, key, object, source, stack) {
|
||||||
if (isObject(objValue)) {
|
if (isObject(objValue) && isObject(srcValue)) {
|
||||||
stack.set(srcValue, objValue);
|
stack.set(srcValue, objValue);
|
||||||
baseMerge(objValue, srcValue, mergeDefaults, stack);
|
baseMerge(objValue, srcValue, mergeDefaults, stack);
|
||||||
}
|
}
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -3658,15 +3658,21 @@
|
|||||||
QUnit.test('should not modify sources', function(assert) {
|
QUnit.test('should not modify sources', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
var object = {},
|
var source1 = { 'a': 1, 'b': { 'c': 2 } },
|
||||||
source1 = { 'a': 1, 'b': { 'c': 2 } },
|
|
||||||
source2 = { 'b': { 'c': 3, 'd': 3 } },
|
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(actual, { 'a': 1, 'b': { 'c': 2, 'd': 3 } });
|
||||||
assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
|
assert.deepEqual(source1, { 'a': 1, 'b': { 'c': 2 } });
|
||||||
assert.deepEqual(source2, { 'b': { 'c': 3, 'd': 3 } });
|
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'] });
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user