mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Ensure _.merge doesn't convert strings to arrays. [closes #1375]
This commit is contained in:
@@ -2327,7 +2327,7 @@
|
|||||||
if (isArray(srcValue) || isTypedArray(srcValue)) {
|
if (isArray(srcValue) || isTypedArray(srcValue)) {
|
||||||
newValue = isArray(oldValue)
|
newValue = isArray(oldValue)
|
||||||
? oldValue
|
? oldValue
|
||||||
: (isArrayLike(oldValue) ? copyArray(oldValue) : []);
|
: ((isObjectLike(oldValue) && isArrayLike(oldValue)) ? copyArray(oldValue) : []);
|
||||||
}
|
}
|
||||||
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
||||||
newValue = isArguments(oldValue)
|
newValue = isArguments(oldValue)
|
||||||
|
|||||||
@@ -10258,7 +10258,7 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should convert values to an array when merging with arrays of `source`', 2, function() {
|
test('should convert values to arrays when merging with arrays of `source`', 2, function() {
|
||||||
var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
|
var object = { 'a': { '1': 'y', 'b': 'z', 'length': 2 } },
|
||||||
actual = _.merge(object, { 'a': ['x'] });
|
actual = _.merge(object, { 'a': ['x'] });
|
||||||
|
|
||||||
@@ -10268,6 +10268,13 @@
|
|||||||
deepEqual(actual, { 'a': [] });
|
deepEqual(actual, { 'a': [] });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not convert strings to arrays when merging with arrays of `source`', 1, function() {
|
||||||
|
var object = { 'a': 'abcdef' },
|
||||||
|
actual = _.merge(object, { 'a': ['x', 'y', 'z'] });
|
||||||
|
|
||||||
|
deepEqual(actual, { 'a': ['x', 'y', 'z'] });
|
||||||
|
});
|
||||||
|
|
||||||
test('should work with a function for `object`', 2, function() {
|
test('should work with a function for `object`', 2, function() {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user