From 0f618596794f2040e590e77fd1b15c69c9b45cea Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 6 Oct 2015 18:38:49 +0200 Subject: [PATCH 1/2] [Validator] added a failing test --- .../Tests/Constraints/UrlValidatorTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 5406b354ce065..e496245c0ae67 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -35,6 +35,13 @@ public function testEmptyStringIsValid() $this->assertNoViolation(); } + public function testEmptyStringFromObjectIsValid() + { + $this->validator->validate(new EmailProvider(), new Url()); + + $this->assertNoViolation(); + } + /** * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException */ @@ -171,3 +178,11 @@ public function getValidCustomUrls() ); } } + +class EmailProvider +{ + public function __toString() + { + return ''; + } +} From e0910d9f493c6dfdc4d1f6ea5a152d3c65a2b1eb Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Sat, 26 Sep 2015 11:31:35 +0300 Subject: [PATCH 2/2] Fix URL validator failure with empty string --- .../Component/Validator/Constraints/UrlValidator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 84bc3d11242a9..51ef8992c6c94 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -41,7 +41,7 @@ class UrlValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { - if (null === $value || '' === $value) { + if (null === $value) { return; } @@ -50,6 +50,10 @@ public function validate($value, Constraint $constraint) } $value = (string) $value; + if ('' === $value) { + return; + } + $pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols)); if (!preg_match($pattern, $value)) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy