8000 Ensure `_.slice` handles a `limit` of `0` in Node 0.10. · lodash/lodash@17e1a6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 17e1a6d

Browse files
committed
Ensure _.slice handles a limit of 0 in Node 0.10.
1 parent 74f6af8 commit 17e1a6d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lodash.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13553,18 +13553,21 @@
1355313553
* // => ['a', 'b']
1355413554
*/
1355513555
function split(string, separator, limit) {
13556-
string = toString(string);
1355713556
if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
1355813557
separator = limit = undefined;
1355913558
}
13559+
limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
13560+
if (!limit) {
13561+
return [];
13562+
}
13563+
string = toString(string);
1356013564
if (string && (
1356113565
typeof separator == 'string' ||
1356213566
(separator != null && !isRegExp(separator))
1356313567
)) {
1356413568
separator += '';
1356513569
if (separator == '' && reHasComplexSymbol.test(string)) {
13566-
var strSymbols = stringToArray(string);
13567-
return limit === undefined ? strSymbols : strSymbols.slice(0, limit >>> 0);
13570+
return baseCastArray(stringToArray(string), 0, limit);
1356813571
}
1356913572
}
1357013573
return string.split(separator, limit);

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23286,7 +23286,7 @@
2328623286
assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']);
2328723287
assert.deepEqual(_.split(string, undefined), [string]);
2328823288
assert.deepEqual(_.split(string, undefined, -1), [string]);
23289-
assert.deepEqual(_.split(string, undefined, 0), string.split(undefined, 0));
23289+
assert.deepEqual(_.split(string, undefined, 0), []);
2329023290

2329123291
var expected = ['A', ' ', leafs, ',', ' ', comboGlyph, ',', ' ', 'a', 'n', 'd', ' ', rocket];
2329223292

0 commit comments

Comments
 (0)
0