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
Regex validator in annotation is inconsistent with the one in PHP #22865
Comments
FYI, there is also a bundle that validate the strength of your https://github.com/rollerworks/PasswordStrengthBundle And there is a repeated type for Passwords in Symfony that displays two password fields (that must be the same). https://symfony.com/doc/current/reference/forms/types/repeated.html#main |
I may be missing something, but why do you need to escape the backslash in the regex in your PHP example? |
@xabbuh I don't know either. It works as expected only when it is escaped, in PHP. |
I agree with @xabbuh. I can't understand why |
Maybe it's related to how Doctrine parses the string, properly new-lines |
@lashae I was not able to reproduce your issue. Can you please create a small example project that show the bug you are experiencing? |
@xabbuh I created an example isolated project and (un)fortunately I cannot reproduce the error either. Interestingly, both validation rules (annotation and php) works with no-escape and unlimited number of escapes... We can close the issue, sorry for the noise. |
I'm building an application on Symfony 3.2
On one part of the application I'm providing an interface my users to change their passwords. For this task, I have a simple form which is bound to my
ChangePasword
entity as follows.Form class:
And the model:
Now, the problem is the regex validator doesn't work. It doesn't match with anything.
However, if I modify the model as below; it works flawlessly:
Further debugging yield that:
For this specific regular expression, the one in the annotation should not escape
\d
bit, however in the PHP implementation (ie usingloadValidatorMetadata
) we need to escape it.If I edit the model which implemented the constraint in annotation as follows, it works:
Just edit
/^(?=.*[a-z])(?=.*\\d).{6,}$/i
to/^(?=.*[a-z])(?=.*\d).{6,}$/i
This seems to inconsistent. If the regex within the annotation is escaped by Symfony than the one in PHP have to be escaped as well or vice versa.
I think the annotation, yaml, xml and PHP implementations need to be identical whereas possible (except for platform limitations) and the documentation should emphasize all of the inconsistencies as verbose as possible.
The text was updated successfully, but these errors were encountered: