diff --git a/lodash.js b/lodash.js index 4cf54fef3..5983b7b83 100644 --- a/lodash.js +++ b/lodash.js @@ -2565,12 +2565,12 @@ if (isArray(srcValue) || isTypedArray(srcValue)) { newValue = isArray(oldValue) ? oldValue - : ((isObject(oldValue) && isArrayLike(oldValue)) ? copyArray(oldValue) : srcValue); + : ((isObject(oldValue) && isArrayLike(oldValue)) ? copyArray(oldValue) : baseClone(srcValue)); } else if (isPlainObject(srcValue) || isArguments(srcValue)) { newValue = isArguments(oldValue) ? toPlainObject(oldValue) - : (isObject(oldValue) ? oldValue : srcValue); + : (isObject(oldValue) ? oldValue : baseClone(srcValue)); } else { isCommon = isFunction(srcValue); diff --git a/test/test.js b/test/test.js index 36f4f0e76..bfb2d2b87 100644 --- a/test/test.js +++ b/test/test.js @@ -12245,17 +12245,31 @@ assert.strictEqual(actual.a, null); }); - QUnit.test('should assign non array/plain-object values directly', function(assert) { + QUnit.test('should assign non array/typed-array/plain-object sources directly', function(assert) { assert.expect(1); function Foo() {} - var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp, new (Uint8Array || noop)], + var values = [new Foo, new Boolean, new Date, Foo, new Number, new String, new RegExp], expected = _.map(values, _.constant(true)); var actual = _.map(values, function(value) { - var object = _.merge({}, { 'a': value }); - return object.a === value; + var object = _.merge({}, { 'value': value }); + return object.value === value; + }); + + assert.deepEqual(actual, expected); + }); + + QUnit.test('should shallow clone array/typed-array/plain-object sources', function(assert) { + assert.expect(1); + + var values = [[], new (Uint8Array || Object), {}], + expected = _.map(values, _.constant(true)); + + var actual = _.map(values, function(value) { + var object = _.merge({}, { 'value': value }); + return object.value !== value && _.isEqual(object.value, value); }); assert.deepEqual(actual, expected);