From 8982578eddb27990e0c820c1b56ec2eacc0d4cee Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 21 Oct 2015 22:05:29 -0700 Subject: [PATCH] Ensure a `_.range` result can start with `-0`. --- lodash.js | 5 ++++- test/test.js | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 799df4b94..69cf59b73 100644 --- a/lodash.js +++ b/lodash.js @@ -12455,9 +12455,12 @@ if (step && isIterateeCall(start, end, step)) { end = step = undefined; } - start = +start || 0; + start = +start; step = step === undefined ? 1 : (+step || 0); + if (start !== start) { + start = 0; + } if (end === undefined) { end = start; start = 0; diff --git a/test/test.js b/test/test.js index 0c0ded3d9..18f51de13 100644 --- a/test/test.js +++ b/test/test.js @@ -14911,6 +14911,13 @@ assert.deepEqual(_.range(21, 10, -3), [21, 18, 15, 12]); }); + QUnit.test('should not coerce `start` of `-0` to `0`', function(assert) { + assert.expect(1); + + var actual = _.range(-0, 1); + assert.strictEqual(1 / actual[0], -Infinity); + }); + QUnit.test('should treat falsey `start` arguments as `0`', function(assert) { assert.expect(13);