-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Regex validator throws exception on invalid input #14943
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
Does it make sense to fix this per validator or does it need to be solved in the validation extension of the Form component? |
Similarly, |
By the way, what I don't understand here: Shouldn't such a request already fail before the validation when the submitted data are mapped to the form? I mean how should an array be mapped to a |
I agree, that would make more sense. |
#20935 when being applied more generally should fix this issue. |
I think that a validator should fail validation if it not receives the expected format; it should not throw an exception.. The same thing happens in LengthValidator here https://github.com/symfony/validator/blob/master/Constraints/LengthValidator.php#L37 and in many other validators. What is the reason of this choice? |
Also related to #13560 |
Thank you all for the discussion. I am going to close here in favour of #12312. |
I have this example, which i use in a small json-api where i use the form component to handle requests and validation.
I have a form field for an accountname. The format of this name is
XX1234
.The validation above works great if the data being validated is a string. If i pass in an array instead of the string i will get an exception that is originating from here:
https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Validator/Constraints/RegexValidator.php#L43
In my opinion the validation should just fail here instead of throwing an exception. I pass an array in, and try to run an regexp on it. It seems obvious to me that something is wrong with the input data then and the validation should fail.
Other validation constraints seems to work this way. Look at this example:
This works. I get an validation error and no exceptions. Other validations contraints, like
Length
seems to have the same problem asRegex
I think it would be great if all constraints just failed if they were passed an array if they cant handle an array. Or is there something i am overseeing?
Is there some way i can work around this to make it fail validation if i pass in an array?
The text was updated successfully, but these errors were encountered: