Skip to content

fix(router): reject non-finite values in convertToNumberIfPossible#7457

Open
yashs33244 wants to merge 1 commit into
refinedev:mainfrom
yashs33244:fix/router-convert-number-non-finite
Open

fix(router): reject non-finite values in convertToNumberIfPossible#7457
yashs33244 wants to merge 1 commit into
refinedev:mainfrom
yashs33244:fix/router-convert-number-non-finite

Conversation

@yashs33244

Copy link
Copy Markdown

convertToNumberIfPossible parses URL pagination params (currentPage/pageSize, typed number | undefined) with a round-trip guard `${num}` === value. Because String(NaN) === "NaN", String(Infinity) === "Infinity", etc., the inputs "NaN", "Infinity", "-Infinity" pass the guard and are returned as the non-finite JS numbers instead of strings — so ?currentPage=NaN yields a non-finite "page number".

This adds Number.isFinite(num) to the guard. The helper is duplicated verbatim in three packages (react-router, remix-router, nextjs-router), all fixed. Adds the first vitest coverage for the helper in each package and a patch changeset.

Red-green proven; a 500k-input fuzz confirms behavior is identical to the old code for every finite value (zero regression). biome + per-package tsc --noEmit clean.

…ossible

The round-trip guard only checked that String(num) === value, which lets the
strings "NaN", "Infinity" and "-Infinity" through as the non-finite numbers
NaN/Infinity/-Infinity. This helper parses the currentPage and pageSize URL
params and its result is typed as number | undefined, so a URL like
?currentPage=NaN produced a non-finite page number instead of leaving it as a
string. Added a Number.isFinite check so only finite numeric strings convert.
Copilot AI review requested due to automatic review settings June 15, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@changeset-bot

changeset-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3ed782a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@refinedev/react-router Patch
@refinedev/remix-router Patch
@refinedev/nextjs-router Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants