diff --git a/src/Symfony/Component/Validator/Constraints/MaxValidator.php b/src/Symfony/Component/Validator/Constraints/MaxValidator.php index 90c9437b2f..18d8e8902e 100644 --- a/src/Symfony/Component/Validator/Constraints/MaxValidator.php +++ b/src/Symfony/Component/Validator/Constraints/MaxValidator.php @@ -31,7 +31,7 @@ class MaxValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { - if (null === $value) { + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Constraints/MinValidator.php b/src/Symfony/Component/Validator/Constraints/MinValidator.php index 4ffe43ab63..a91d873864 100644 --- a/src/Symfony/Component/Validator/Constraints/MinValidator.php +++ b/src/Symfony/Component/Validator/Constraints/MinValidator.php @@ -31,7 +31,7 @@ class MinValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { - if (null === $value) { + if (null === $value || '' === $value) { return; } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/MaxValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/MaxValidatorTest.php index f86b5109d8..3ee95eeb69 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/MaxValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/MaxValidatorTest.php @@ -40,6 +40,14 @@ class MaxValidatorTest extends \PHPUnit_Framework_TestCase $this->validator->validate(null, new Max(array('limit' => 10))); } + public function testEmptyStringIsValid() + { + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate('', new Max(array('limit' => 10))); + } + /** * @dataProvider getValidValues */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/MinValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/MinValidatorTest.php index fb103ce983..f760190b2d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/MinValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/MinValidatorTest.php @@ -34,6 +34,14 @@ class MinValidatorTest extends \PHPUnit_Framework_TestCase $this->validator->validate(null, new Min(array('limit' => 10))); } + public function testEmptyStringIsValid() + { + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate('', new Min(array('limit' => 10))); + } + /** * @dataProvider getValidValues */