Ensure _.merge doesn't convert strings to arrays. [closes #1375]

This commit is contained in:
John-David Dalton
2015-07-30 08:10:22 -07:00
parent 693704a832
commit 3935d5f2f7
2 changed files with 9 additions and 2 deletions

View File

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

View File

@@ -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() {}