diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 8b27f34bc7..7144d2cff8 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -21,7 +21,7 @@ class DateTimeValidator extends ConstraintValidator public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index df855626cd..f9b4d88944 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -21,7 +21,7 @@ class DateValidator extends ConstraintValidator public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index 3d00082964..f3b5981123 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -21,7 +21,7 @@ class EmailValidator extends ConstraintValidator public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index e188e55bfd..0ed3655557 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -21,7 +21,7 @@ class FileValidator extends ConstraintValidator { public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php b/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php index 90268ca50e..e428676db4 100644 --- a/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php @@ -19,7 +19,7 @@ class MaxLengthValidator extends ConstraintValidator { public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php b/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php index f12d95d7d9..c0eeeeeaba 100644 --- a/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php @@ -19,7 +19,7 @@ class MinLengthValidator extends ConstraintValidator { public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index 6f60e336f7..3e58dfd09d 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -19,7 +19,7 @@ class RegexValidator extends ConstraintValidator { public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index 062a1cef89..c0724c197e 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -21,7 +21,7 @@ class TimeValidator extends ConstraintValidator public function isValid($value, Constraint $constraint) { - if ($value === null) { + if ($value === null || $value === '') { return true; } diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/DateTimeValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/DateTimeValidatorTest.php index 57fed42cf6..4bcbfe4db4 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/DateTimeValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/DateTimeValidatorTest.php @@ -19,6 +19,11 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new DateTime())); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new DateTime())); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php index 714581978f..fd7bd852d2 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php @@ -19,6 +19,11 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new Date())); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new Date())); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/EmailValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/EmailValidatorTest.php index ddf28731b3..f4fb8ce7c9 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/EmailValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/EmailValidatorTest.php @@ -19,6 +19,11 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new Email())); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new Email())); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php index e0e70afcf3..22c0621286 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php @@ -28,6 +28,11 @@ class FileValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new File())); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new File())); + } + public function testExpectsStringCompatibleTypeOrFile() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/MaxLengthValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/MaxLengthValidatorTest.php index 0780a34b73..091e9bbc0a 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/MaxLengthValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/MaxLengthValidatorTest.php @@ -19,6 +19,11 @@ class MaxLengthValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new MaxLength(array('limit' => 5)))); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new MaxLength(array('limit' => 5)))); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/MinLengthValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/MinLengthValidatorTest.php index 58676e01ea..6475418478 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/MinLengthValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/MinLengthValidatorTest.php @@ -19,6 +19,11 @@ class MinLengthValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new MinLength(array('limit' => 6)))); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new MinLength(array('limit' => 6)))); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/RegexValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/RegexValidatorTest.php index 2843e2e1d3..993e982cf7 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/RegexValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/RegexValidatorTest.php @@ -19,6 +19,11 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new Regex(array('pattern' => '/^[0-9]+$/')))); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new Regex(array('pattern' => '/^[0-9]+$/')))); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/TimeValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/TimeValidatorTest.php index 25d2dc2656..6cf34e08d5 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/TimeValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/TimeValidatorTest.php @@ -19,6 +19,11 @@ class TimeValidatorTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->validator->isValid(null, new Time())); } + public function testEmptyStringIsValid() + { + $this->assertTrue($this->validator->isValid('', new Time())); + } + public function testExpectsStringCompatibleType() { $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');