Parcourir la source

[Validator] Fixed UrlValidator to accept empty strings (closes #9297)

Gustavo Falco il y a 14 ans
Parent
commit
af291bb0f1

+ 1 - 1
src/Symfony/Component/Validator/Constraints/UrlValidator.php

@@ -30,7 +30,7 @@ class UrlValidator extends ConstraintValidator
 
     public function isValid($value, Constraint $constraint)
     {
-        if ($value === null) {
+        if ($value === null || $value === '') {
             return true;
         }
 

+ 5 - 0
tests/Symfony/Tests/Component/Validator/Constraints/UrlValidatorTest.php

@@ -19,6 +19,11 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($this->validator->isValid(null, new Url()));
     }
 
+    public function testEmptyStringIsValid()
+    {
+        $this->assertTrue($this->validator->isValid('', new Url()));
+    }
+
     public function testExpectsStringCompatibleType()
     {
         $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');