-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[validator] ctype validators do not respect integer values #38278
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
That would a minor BC. I also wonder if it is a good idea to have a constraint for natural numbers. |
That's how the |
@xabbuh I want to validate that a value is digit. As of |
If you want to validate that the value is an integer,
I disagree. We mention this explicitly in the documentation. |
I did not notice it. Anyway I think currently the type validator solves two completely different tasks.
That brings some inconsistency and confusion. |
I think you're looking for btw edit: hm so does |
is there any reason to not use the int type (+ Positive[OrZero] constraint) actually? |
Such a validator would not be accurate on wrong string values from user input. var_dump((int) 'Wrong value'); // int(0) By the way unlike For the reference here is the implementation of |
I think it's related to #35316 also (depending if integer is your actual domain type), but ultimately there's no validation currently for So |
Another example of inaccurate validation. $violations = Validation::createValidator()->validate('wrong value', new EqualTo(0));
echo count($violations); // 0 Such behaviour may potentially cause security implications in some cases. |
I think the correct approach to deal with this would be using safe casters wherever it possible. The corresponding RFC in PHP was declained but there is a polifill. |
This is PHP :) there's both loose and strict comparison at the language level: Safe casting is interesting but still needs to be implemented per case, as a normalization step; back to # #35316 :) What i think is the best approach currently, is introducing our own This is also the most obvious decision path for users, either edit: IIUC |
I think currently Basically all types can be classified in two categories:
Mixing them is a source of bugs and confusion. I would check with As of To my mind safe casting worths having a separate component because it can be helpful outside of validator. For instance the behaviour of |
i've no strong opinion on naming/code locations :) but i'd say values fit into 2 different categories
Technically and semantically all these fit |
Hey, thanks for your report! |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Symfony version(s) affected: master
Description
ctype_digit() excepts all numbers to be strings (like: "123") and does not validate real integers (like: 123).
How to reproduce
Triggers the following violation.
Possible Solution
Cast the value to string before validation.
The text was updated successfully, but these errors were encountered: