Repository navigation
Conversation
resolveNumericOption accepted any integer >= 0, so a limit of 0 reached Math.ceil(totalItems / limit) and produced Infinity, or NaN when there were no results. Both serialise to null over JSON, and the last link came out as ?page=Infinity&limit=0. Applies a minimum of 1 to limit so it takes the existing invalid-input path and falls back to the default, matching how 'x', decimals and negatives are already handled. page keeps a minimum of 0, since paginateRepository has an explicit branch returning an empty page for it.
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.
Summary
A
limitof 0 is currently accepted, and it makestotalPagesa division by zero.resolveNumericOptionguards withresolvedValue >= 0, so0passes straight through toMath.ceil(totalItems / limit).Reproduced against a repository holding 10 entities:
Two things go wrong there.
totalPagesisInfinity, whichJSON.stringifywrites asnull, so an API consumer sees a null where a number is documented. Andlinks.lastbecomes?page=Infinity&limit=0, which is not a usable URL.With no results at all it is
NaN / 0instead, which also serialises tonull.This matters because
limitusually arrives straight off a query string, and?limit=0is an easy thing for a caller to send.The fix
resolveNumericOptionnow applies a minimum of 1 tolimitwhile leavingpageat 0:A
limitof 0 therefore takes the existing invalid-input path — the warning that is already in place fires, and it falls back to the default of 10. That felt more consistent than throwing, since the function already treats'x',1.5and negatives that way.pageis deliberately untouched.paginateRepositoryhas an explicitpage < 1branch that returns an empty pagination object, and there are tests covering it, so 0 stays valid there. I added a test pinning that down so the distinction does not get lost later.Tests
Three added to
paginate.repository.spec.ts:replaces a limit of 0 with the default of 10— covers the items, the meta and the warningkeeps totalPages serialisable when limit is 0— round-trips the meta throughJSON.parse(JSON.stringify(...)), which is where theInfinityactually bitesstill accepts a page of 0— guards the behaviour I did not want to changeThe first two fail before the change and pass after:
One caveat on how I verified this. I ran the mock-backed suites (
paginate.repository.spec,paginate.meta.transform.spec) andtsc --noEmit, both clean. I did not run the MySQL-backed suites, since I did not have the container up. The change is confined toresolveNumericOption, which every entry point shares, so I would not expect it to reach them differently — but worth a look on your side before merging.While setting up I noticed
docker-compose.ymlreadsenv_file: .envand the repo ships.env.dist, with no note in the README about copying it. Happy to send a short "running the tests" section separately if that would save the next person the detour.