Add isBuffer checks to baseMerge and _.transform.

This commit is contained in:
John-David Dalton
2016-10-03 18:05:32 -07:00
parent 8592f4163f
commit 0eca941e22

View File

@@ -3574,7 +3574,7 @@
if (object === source) { if (object === source) {
return; return;
} }
if (!(isArray(source) || isTypedArray(source))) { if (!(isArray(source) || isBuffer(source) || isTypedArray(source))) {
var props = baseKeysIn(source); var props = baseKeysIn(source);
} }
arrayEach(props || source, function(srcValue, key) { arrayEach(props || source, function(srcValue, key) {
@@ -13647,22 +13647,23 @@
* // => { '1': ['a', 'c'], '2': ['b'] } * // => { '1': ['a', 'c'], '2': ['b'] }
*/ */
function transform(object, iteratee, accumulator) { function transform(object, iteratee, accumulator) {
var isArr = isArray(object) || isTypedArray(object); var isArr = isArray(object),
iteratee = getIteratee(iteratee, 4); isArrLike = isArr || isBuffer(object) || isTypedArray(object);
iteratee = getIteratee(iteratee, 4);
if (accumulator == null) { if (accumulator == null) {
if (isArr || isObject(object)) { var Ctor = object && object.constructor;
var Ctor = object.constructor; if (isArrLike) {
if (isArr) { accumulator = isArr ? new Ctor : [];
accumulator = isArray(object) ? new Ctor : []; }
} else { else if (isObject(object)) {
accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
} }
} else { else {
accumulator = {}; accumulator = {};
} }
} }
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) { (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
return iteratee(accumulator, value, index, object); return iteratee(accumulator, value, index, object);
}); });
return accumulator; return accumulator;