-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Type
constraint considers NAN
and INF
as floats
#50782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Type
constraint allows NAN
and INF
as floatsType
constraint considers NAN
and INF
as floats
@aprat84 Sounds reasonable to me, can you open a PR with your suggestion (against the |
Maybe the best solution would be to add a new constraint
Instead of patching the |
Hello, I made an attemps to create |
Both NaN and Inf are valid floats as defined in IEEE 754. It would be very strange to treat them as invalid values. |
…inite-float` and `finite-number` validations (guillaume-a) This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Update `Type` constraint, add `number`, `finite-float` and `finite-number` validations Documentation for PR * symfony/symfony#50907 Related to * symfony/symfony#50782 This is my first sf-docs PR, please tell me if I did anything wrong. Thank you. Commits ------- 458fdd5 [Validator] Update `Type` constraint, add `number`, `finite-float` and `finite-number` validations
Symfony version(s) affected
6.3
Description
If a number is outside of
2.2250738585072014E-308
to1.7976931348623158E+308
range, PHP converts it to-INF
orINF
.Values
INF
,-INF
andNAN
are consideredfloat
in PHP as for theis_float
function.The
Type
constraint relies in this function to check for a valid float.Now, are this valid float numbers? IMHO no.
FTR: this doesn't happen with integers, as PHP converts them to float once they go outside the
PHP_INT_MIN
andPHP_INT_MAX
range...How to reproduce
Possible Solution
Add an extra check for
is_finite
, when dealing with floats?Additional Context
No response
The text was updated successfully, but these errors were encountered: