mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Ensure _.merge skips merging when object and source are the same value.
This commit is contained in:
@@ -2529,6 +2529,9 @@
|
||||
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
||||
*/
|
||||
function baseMerge(object, source, customizer, stackA, stackB) {
|
||||
if (object === source) {
|
||||
return;
|
||||
}
|
||||
var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source);
|
||||
arrayEach(props || source, function(srcValue, key) {
|
||||
if (props) {
|
||||
|
||||
22
test/test.js
22
test/test.js
@@ -12293,6 +12293,28 @@
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should skip merging when `object` and `source` are the same value', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (defineProperty) {
|
||||
var object = {},
|
||||
pass = true;
|
||||
|
||||
defineProperty(object, 'a', {
|
||||
'enumerable': true,
|
||||
'configurable': true,
|
||||
'get': function() { pass = false; },
|
||||
'set': function() { pass = false; }
|
||||
});
|
||||
|
||||
_.merge(object, object);
|
||||
assert.ok(pass);
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should convert values to arrays when merging with arrays of `source`', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user