From 3935d5f2f710cb074683066896818bbb8ec7bddd Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 30 Jul 2015 08:10:22 -0700 Subject: [PATCH] Ensure `_.merge` doesn't convert strings to arrays. [closes #1375] --- lodash.js | 2 +- test/test.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index a2668d4f6..91339ef7d 100644 --- a/lodash.js +++ b/lodash.js @@ -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) diff --git a/test/test.js b/test/test.js index 5a51d52f0..fb891faeb 100644 --- a/test/test.js +++ b/test/test.js @@ -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() {}