From b3a54117c8c5fab8daea37565e98478b45bc9af2 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Fri, 16 Oct 2015 14:11:32 +0100 Subject: [PATCH] [Validator] Allow an empty path in a URL with only a fragment or a query --- src/Symfony/Component/Validator/Constraints/UrlValidator.php | 2 +- .../Validator/Tests/Constraints/UrlValidatorTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 51ef8992c6..5af71e6d82 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -33,7 +33,7 @@ class UrlValidator extends ConstraintValidator \] # a IPv6 address ) (:[0-9]+)? # a port (optional) - (/?|/\S+) # a /, nothing or a / with something + (/?|/\S+|\?|\#) # a /, nothing, a / with something, a query or a fragment $~ixu'; /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index e496245c0a..c08531339c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -111,6 +111,8 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest array('http://☎.com/'), array('http://username:password@symfony.com'), array('http://user-name@symfony.com'), + array('http://symfony.com?'), + array('http://symfony.com#'), ); } @@ -140,8 +142,6 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest array('http://goog_le.com'), array('http://google.com::aa'), array('http://google.com:aa'), - array('http://symfony.com?'), - array('http://symfony.com#'), array('ftp://google.fr'), array('faked://google.fr'), array('http://127.0.0.1:aa/'),