mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +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)) {
|
||||
newValue = isArray(oldValue)
|
||||
? oldValue
|
||||
: (isArrayLike(oldValue) ? copyArray(oldValue) : []);
|
||||
: ((isObjectLike(oldValue) && isArrayLike(oldValue)) ? copyArray(oldValue) : []);
|
||||
}
|
||||
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
||||
newValue = isArguments(oldValue)
|
||||
|
||||
@@ -10258,7 +10258,7 @@
|
||||
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 } },
|
||||
actual = _.merge(object, { 'a': ['x'] });
|
||||
|
||||
@@ -10268,6 +10268,13 @@
|
||||
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() {
|
||||
function Foo() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user