Skip to content

fix(number): reject strings that coerce to integers by precision loss - #2366

Closed
draarivpatel-ui wants to merge 1 commit into
jquense:masterfrom
draarivpatel-ui:fix-integer-precision-coercion
Closed

draarivpatel-ui wants to merge 1 commit into
jquense:masterfrom
draarivpatel-ui:fix-integer-precision-coercion

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #2042

number().integer() reported strings like '4.9999999999999999999' as valid integers. The transform parses the string with +parsed, where precision loss rounds it to 5, and the integer test then only checked the coerced value.

The test now also verifies that a string original value denotes an integer exactly: after applying any exponent, every digit in a fractional position must be zero. '4.9999999999999999999' and '5.0000000000000000000001' are rejected, while '5.0', '1e3', ' 5 ', and '-4.99e2' remain valid. Non-decimal strings keep the previous behavior.

number().integer() validated strings like '4.9999999999999999999' as
integers because float parsing rounds them to 5. The integer test now
checks that a string original value denotes an integer exactly: every
digit in a fractional position (after applying the exponent) must be
zero. Non-decimal strings keep the previous behavior.

Fixes jquense#2042
Copilot AI balanced review requested due to automatic review settings November 24, 2026 20:15

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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.

Long serialized floats validate as integers when coerced.

2 participants