From e9f5f130e87987ec739573a42f4e8337762a91b9 Mon Sep 17 00:00:00 2001 From: Christopher Hall Date: Wed, 2 May 2012 16:23:18 -0700 Subject: [PATCH 1/2] Added test Min/Max validators should ignore empty string Refs #3686 --- .../Validator/Tests/Constraints/MaxValidatorTest.php | 8 ++++++++ .../Validator/Tests/Constraints/MinValidatorTest.php | 8 ++++++++ 2 files changed, 16 insertions(+) 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 */ From f30bf36d85b7b54bce2030d263cf77cddcd86141 Mon Sep 17 00:00:00 2001 From: Christopher Hall Date: Wed, 2 May 2012 16:28:47 -0700 Subject: [PATCH 2/2] Min/Max Validators ignore empty string Fixes #3686 --- src/Symfony/Component/Validator/Constraints/MaxValidator.php | 2 +- src/Symfony/Component/Validator/Constraints/MinValidator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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; }