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:
John-David Dalton
2012-09-07 21:09:21 -07:00
parent f7297b84e7
commit 958ac72805
2 changed files with 9 additions and 5 deletions

View File

@@ -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' +

View File

@@ -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));
/*--------------------------------------------------------------------------*/