[Validator] add IPv6 support to UrlValidator

This commit is contained in:
Igor Wiedler 2011-04-22 16:28:55 +02:00
parent 82699c5a98
commit afcdbf8b79
2 changed files with 9 additions and 3 deletions

View File

@ -20,9 +20,13 @@ class UrlValidator extends ConstraintValidator
const PATTERN = '~^
(%s):// # protocol
(
([a-z0-9-]+\.)+[a-z]{2,6} # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address
([a-z0-9-]+\.)+[a-z]{2,6} # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address
| # or
\[
[0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,5}((:[0-9a-fA-F]{0,4}){1,2}|:([\d\.]+))
\] # a IPv6 address
)
(:[0-9]+)? # a port (optional)
(/?|/\S+) # a /, nothing or a / with something

View File

@ -57,6 +57,8 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
array('http://www.symfony.com/'),
array('http://127.0.0.1/'),
array('http://127.0.0.1:80/'),
array('http://[::1]/'),
array('http://[::1]:80/'),
);
}