-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
RegexValidator not working properly with "match" option set to "false" #5603
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
Addendum: This is with Symfony 2.1.2-dev |
A shorter fix than described in the blog would be:
|
Can you paste your mapping for the constraint ? |
Example:
If the |
The bug is in fact in the XmlFileLoader of the validator component. It does not apply the converting rules used in other components for values. |
btw, using your suggested fix is wrong. It would break it for people using Yaml, PHP or annotations (where defining a boolean as possible natively, without having to hack something in the loader to convert the value) |
It was just a 5 minute hack that "worked for me (tm)". Seems like you already found the real culprit. (Friendly question:) Do you have an ETA for a patch? This is blocking some code from going into production over here. |
Workaround: use 0 instead of "false". Works in 2.3.3 version. Example: <constraint name="Regex">
<option name="pattern">/\s/</option>
<option name="match">0</option>
<option name="message">The value cannot contain spaces</option>
</constraint> |
#8831 should fix this issue. |
This PR was merged into the 2.2 branch. Discussion ---------- [Validator] fixed Boolean handling in XML constraint mappings | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #5603 | License | MIT | Doc PR | n/a ping @bschussek Commits ------- 33b0a17 [Validator] fixed Boolean handling in XML constraint mappings (closes #5603)
* 2.2: [Locale] Fixed: StubLocale::setDefault() throws no exception when "en" is passed [Yaml] fixed embedded folded string parsing [Validator] fixed Boolean handling in XML constraint mappings (closes #5603) Conflicts: src/Symfony/Component/Locale/Stub/StubLocale.php src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php
* 2.3: Clear lazy loading initializer after the service is successfully initialized [FrameworkBundle] added support for double-quoted strings in the extractor (closes #8797) [SecurityBundle] Move format-dependent tests from SecurityExtensionTest bumped Symfony version to 2.3.5-DEV updated VERSION for 2.3.4 updated CHANGELOG for 2.3.4 bumped Symfony version to 2.2.7 updated VERSION for 2.2.6 update CONTRIBUTORS for 2.2.6 updated CHANGELOG for 2.2.6 clearToken exception is thrown at wrong place. fix typo in test skipped message [Form] Fixed Form::all() signature for PHP 5.3.3 [Form] Fixed Form::all() signature for PHP 5.3.3 [Locale] Fixed: Locale::setDefault() throws no exception when "en" is passed [Locale] Fixed: StubLocale::setDefault() throws no exception when "en" is passed [Translation] Grammar fix [Yaml] fixed embedded folded string parsing [Validator] fixed Boolean handling in XML constraint mappings (closes #5603) [Translation] Fixed regression: When only one rule is passed to transChoice(), this rule should be used Conflicts: src/Symfony/Component/HttpKernel/Kernel.php
I was trying to use the RegexValidator with the "match" option set to "false". This leads to incorrect behavior, i.e. the validator keeps raising errors for fields that definitely do not match the Regex.
The code in question is here.
The issue appears to be that the "match" parameter is maintained as a string when set to false and then
xor
ed upon.I found this blog that explains the problem in more detail. I couldn't find a corresponding bug that was reported by this person, so I'm reporting it now. The patch described there works for me.
The text was updated successfully, but these errors were encountered: