mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Ensure the internal stack argument of _.merge doesn't pave the 4th argument passed to it. [closes #69]
Former-commit-id: b33e1cb7795294b9481e2c9c6888d0f37419208d
This commit is contained in:
@@ -1817,22 +1817,21 @@
|
||||
* // => [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }]
|
||||
*/
|
||||
var merge = createIterator(extendIteratorOptions, {
|
||||
'args': 'object, source, indicator, stack',
|
||||
'args': 'object, source, indicator',
|
||||
'top':
|
||||
'var destValue, found, isArr, stackLength, recursive = indicator == isPlainObject;\n' +
|
||||
'if (!recursive) stack = [];\n' +
|
||||
'var isArr, recursive = indicator == isPlainObject, stack = recursive ? arguments[3] : [];\n' +
|
||||
'for (var argsIndex = 1, argsLength = recursive ? 2 : arguments.length; argsIndex < argsLength; argsIndex++) {\n' +
|
||||
' if (iteratee = arguments[argsIndex]) {',
|
||||
'inLoop':
|
||||
'if (value && ((isArr = isArray(value)) || isPlainObject(value))) {\n' +
|
||||
' found = false; stackLength = stack.length;\n' +
|
||||
' var found = false, stackLength = stack.length;\n' +
|
||||
' while (stackLength--) {\n' +
|
||||
' if (found = stack[stackLength].source == value) break\n' +
|
||||
' }\n' +
|
||||
' if (found) {\n' +
|
||||
' result[index] = stack[stackLength].value\n' +
|
||||
' } else {\n' +
|
||||
' destValue = (destValue = result[index]) && isArr\n' +
|
||||
' var destValue = (destValue = result[index]) && isArr\n' +
|
||||
' ? (isArray(destValue) ? destValue : [])\n' +
|
||||
' : (isPlainObject(destValue) ? destValue : {});\n' +
|
||||
' stack.push({ value: destValue, source: value });\n' +
|
||||
|
||||
@@ -1002,6 +1002,11 @@
|
||||
var actual = _.merge(object, source);
|
||||
equal(_.isArguments(actual.args), false);
|
||||
});
|
||||
|
||||
test('should work with four arguments', function() {
|
||||
var expected = { 'a': 4 };
|
||||
deepEqual(_.merge({ 'a': 1 }, { 'a': 2 }, { 'a': 3 }, expected), expected);
|
||||
});
|
||||
}(1, 2, 3));
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user