From 17e1a6dbe84e1debc15af55c0988602544cebf04 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 9 Apr 2016 00:53:07 -0700 Subject: [PATCH] Ensure `_.slice` handles a `limit` of `0` in Node 0.10. --- lodash.js | 9 ++++++--- test/test.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 4159a53ac..26578fece 100644 --- a/lodash.js +++ b/lodash.js @@ -13553,18 +13553,21 @@ * // => ['a', 'b'] */ function split(string, separator, limit) { - string = toString(string); if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { separator = limit = undefined; } + limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0; + if (!limit) { + return []; + } + string = toString(string); if (string && ( typeof separator == 'string' || (separator != null && !isRegExp(separator)) )) { separator += ''; if (separator == '' && reHasComplexSymbol.test(string)) { - var strSymbols = stringToArray(string); - return limit === undefined ? strSymbols : strSymbols.slice(0, limit >>> 0); + return baseCastArray(stringToArray(string), 0, limit); } } return string.split(separator, limit); diff --git a/test/test.js b/test/test.js index 51db4e967..273e8bc19 100644 --- a/test/test.js +++ b/test/test.js @@ -23286,7 +23286,7 @@ assert.deepEqual(_.split(string, ' ', 3), ['A', leafs + ',', comboGlyph + ',']); assert.deepEqual(_.split(string, undefined), [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];