bug #11601 [Validator] Allow basic auth in url when using UrlValidator. (blaugueux)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11601).
Discussion
----------
[Validator] Allow basic auth in url when using UrlValidator.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Now an url with basic auth like ```http://username:password@symfony.com``` can be valid.
Commits
-------
f1ea987
Allow basic auth in url. Improve regex. Add tests.
This commit is contained in:
commit
64543909f8
@ -24,6 +24,7 @@ class UrlValidator extends ConstraintValidator
|
|||||||
{
|
{
|
||||||
const PATTERN = '~^
|
const PATTERN = '~^
|
||||||
(%s):// # protocol
|
(%s):// # protocol
|
||||||
|
(([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth
|
||||||
(
|
(
|
||||||
([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
|
([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
|
||||||
| # or
|
| # or
|
||||||
|
@ -116,6 +116,8 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('http://xn--espaa-rta.xn--ca-ol-fsay5a/'),
|
array('http://xn--espaa-rta.xn--ca-ol-fsay5a/'),
|
||||||
array('http://xn--d1abbgf6aiiy.xn--p1ai/'),
|
array('http://xn--d1abbgf6aiiy.xn--p1ai/'),
|
||||||
array('http://☎.com/'),
|
array('http://☎.com/'),
|
||||||
|
array('http://username:password@symfony.com'),
|
||||||
|
array('http://user-name@symfony.com'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +157,10 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('ftp://[::1]/'),
|
array('ftp://[::1]/'),
|
||||||
array('http://[::1'),
|
array('http://[::1'),
|
||||||
array('http://hello.☎/'),
|
array('http://hello.☎/'),
|
||||||
|
array('http://:password@symfony.com'),
|
||||||
|
array('http://:password@@symfony.com'),
|
||||||
|
array('http://username:passwordsymfony.com'),
|
||||||
|
array('http://usern@me:password@symfony.com'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user