fix(victory-core): range() drops start value when end is 0#3084
Open
chatman-media wants to merge 1 commit into
Open
fix(victory-core): range() drops start value when end is 0#3084chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
Helpers.range used a truthy check to decide whether an end argument was supplied, so a literal 0 end was treated as no end given. range(5, 0) returned [0, 1, 2, 3, 4] instead of the expected descending [5, 4, 3, 2, 1] (consistent with range(5, -5)), and range(10, 0, 2) returned an ascending sequence from 0. Detect the end argument by presence (end === undefined) instead of truthiness.
|
@chatman-media is attempting to deploy a commit to the formidable-labs Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 6eada88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Helpers.rangedecides whether anendargument was supplied using a truthy check (end ? ... : ...). A literal0end is falsy, so it is mistaken for "no end given" and thestartvalue is silently dropped:This is inconsistent with every other descending case the function already supports —
range(5, -5)andrange(5, 1)both correctly descend; only theend === 0case misbehaves, and0is the single value that trips the truthy check. The expected descending behavior matches the function's own existing tests (range(5, -5)→ descending) and lodash's_.range(5, 0)→[5, 4, 3, 2, 1].The JSDoc already describes the intent in terms of presence — "@param end [The end value] If this is defined, start is the start value" — so the truthy check is simply the wrong test.
Fix
Detect the
endargument by presence (end === undefined) instead of truthiness. The follow-upif (!endIndex) endIndex = 0guard is retained (and its comment clarified) so thatrange(NaN)/range()keep returning[]as before.Tests
range(5, 0)andrange(10, 0, 2). Both fail onmain(2 failed, 41 passed) and pass with the fix (43 passed).helpers.test.tscases still pass —range(4),range(-4),range(1, 5),range(-5, 5),range(5, -5), increment cases, the floating-point length case, and theundefined/NaNstart cases are unchanged.victory-corepatch).