Skip to content

[Validator] Expression validator now processes null values #11709

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

Merged
merged 1 commit into from
Aug 31, 2014

Conversation

tommygnr
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? yes(minor)
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

The ExpressionValidator was incorrectly skipping validation of null or empty string values.

For example the following was (incorrectly) considered valid if hairColour is null because the validator was skipped

<?php

namespace Acme\DemoBundle\Model\Person;

use Symfony\Component\Validator\Constraints as Assert;

class Person
{
    private $hasHair;

    /**
     * @Assert\Expression(
     *     "!(this.hasHair() and value == null)",
     *     message="If you have hair you must pick its colour!"
     * )
     */
    private $hairColour;
}

This is a follow on from #11590 but is targeted against master as the BC break introduced was considered undesirable for currently released versions of symfony.

I will squash and create a documentation PR once there is consensus that this is ready to be merged.

@stof
Copy link
Member

stof commented Aug 19, 2014

This must be documented in the component changelog for 2.6 (prefixed with [BC Break] and in the UDGRADE-2.6 file (as it is a BC break)

@tommygnr
Copy link
Contributor Author

@stof I will do that once it is agreed that this can be merged. I have restricted it to a rebase of #11590 until there is agreement about exactly what to do.

@webmozart webmozart changed the title Expression validator [Validator] Expression validator now processes null values Aug 20, 2014
@stof
Copy link
Member

stof commented Aug 20, 2014

I will do that once it is agreed that this can be merged

I don't understand the reasoning: it cannot be merged without the changelog update requested

@xabbuh
Copy link
Member

xabbuh commented Aug 20, 2014

@stof As far as I understand, @tommygnr wanted to know whether or not the way he fixed the issue is approriate before investing more time in this (mainly because of the BC break I think).

@stof
Copy link
Member

stof commented Aug 20, 2014

Well, the discussion in the previous PR already indicate that we agreed abotu merging such change in master (the reason the PR was replaced is that we rejected changing this behavior in 2.4).
And the way to fix it is the only one (removing the check for null and empty strings).

IMO, the only thing missing to make it mergeable is precisely the changelog update

The ExpressionValidator was incorrectly skipping validation of null or
empty string values.
@tommygnr tommygnr force-pushed the expression-validator branch from cbade6b to 580e1a7 Compare August 21, 2014 06:51
@tommygnr
Copy link
Contributor Author

@xabbuh was on the money. Anyway, since I am now clear that the approach I took is acceptable I have added the required changelog entries. @stof let me know if you are happy with the wording of those entries.

@fabpot
Copy link
Member

fabpot commented Aug 28, 2014

👍

1 similar comment
@stof
Copy link
Member

stof commented Aug 28, 2014

👍

@fabpot
Copy link
Member

fabpot commented Aug 31, 2014

Thank you @tommygnr.

@fabpot fabpot merged commit 580e1a7 into symfony:master Aug 31, 2014
fabpot added a commit that referenced this pull request Aug 31, 2014
…lues (tommygnr)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Expression validator now processes null values

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes(minor)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The ExpressionValidator was incorrectly skipping validation of null or empty string values.

For example the following was (incorrectly) considered valid if hairColour is null because the validator was skipped
```php
<?php

namespace Acme\DemoBundle\Model\Person;

use Symfony\Component\Validator\Constraints as Assert;

class Person
{
    private $hasHair;

    /**
     * @Assert\Expression(
     *     "!(this.hasHair() and value == null)",
     *     message="If you have hair you must pick its colour!"
     * )
     */
    private $hairColour;
}
```

This is a follow on from #11590 but is targeted against master as the BC break introduced was considered undesirable for currently released versions of symfony.

I will squash and create a documentation PR once there is consensus that this is ready to be merged.

Commits
-------

580e1a7 [Validator] fixed: Expressions always valid for null values
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Oct 19, 2014
…nstraint in 2.6) (xabbuh)

This PR was merged into the master branch.

Discussion
----------

[Reference][Constraints] validate `null` (Expression constraint in 2.6)

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#11709)
| Applies to    | 2.6
| Fixed tickets | master part of #4191

Since Symfony 2.6, the Expression constraint doesn't skip validating `null` values.

Probably, it's a good idea to merge #4202 first and rebase this then to avoid merge conflicts.

Commits
-------

fb18056 validate `null` (Expression constraint in 2.6)
@webdevilopers
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants