Ensure _.slice handles a limit of 0 in Node 0.10.

This commit is contained in:
John-David Dalton
2016-04-09 00:53:07 -07:00
parent 74f6af8686
commit 17e1a6dbe8
2 changed files with 7 additions and 4 deletions

View File

@@ -13553,18 +13553,21 @@
* // => ['a', 'b'] * // => ['a', 'b']
*/ */
function split(string, separator, limit) { function split(string, separator, limit) {
string = toString(string);
if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
separator = limit = undefined; separator = limit = undefined;
} }
limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
if (!limit) {
return [];
}
string = toString(string);
if (string && ( if (string && (
typeof separator == 'string' || typeof separator == 'string' ||
(separator != null && !isRegExp(separator)) (separator != null && !isRegExp(separator))
)) { )) {
separator += ''; separator += '';
if (separator == '' && reHasComplexSymbol.test(string)) { if (separator == '' && reHasComplexSymbol.test(string)) {
var strSymbols = stringToArray(string); return baseCastArray(stringToArray(string), 0, limit);
return limit === undefined ? strSymbols : strSymbols.slice(0, limit >>> 0);
} }
} }
return string.split(separator, limit); return string.split(separator, limit);

View File

@@ -23286,7 +23286,7 @@
assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']); assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']);
assert.deepEqual(_.split(string, undefined), [string]); assert.deepEqual(_.split(string, undefined), [string]);
assert.deepEqual(_.split(string, undefined, -1), [string]); assert.deepEqual(_.split(string, undefined, -1), [string]);
assert.deepEqual(_.split(string, undefined, 0), string.split(undefined, 0)); assert.deepEqual(_.split(string, undefined, 0), []);
var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket]; var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket];