Skip to content

Commit 6454390

Browse files
committed
bug symfony#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 symfony#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.
2 parents 7b3bd56 + f1ea987 commit 6454390

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Symfony/Component/Validator/Constraints/UrlValidator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class UrlValidator extends ConstraintValidator
2424
{
2525
const PATTERN = '~^
2626
(%s):// # protocol
27+
(([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth
2728
(
2829
([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
2930
| # or

src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function getValidUrls()
116116
array('http://xn--espaa-rta.xn--ca-ol-fsay5a/'),
117117
array('http://xn--d1abbgf6aiiy.xn--p1ai/'),
118118
array('http://☎.com/'),
119+
array('http://username:password@symfony.com'),
120+
array('http://user-name@symfony.com'),
119121
);
120122
}
121123

@@ -155,6 +157,10 @@ public function getInvalidUrls()
155157
array('ftp://[::1]/'),
156158
array('http://[::1'),
157159
array('http://hello.☎/'),
160+
array('http://:password@symfony.com'),
161+
array('http://:password@@symfony.com'),
162+
array('http://username:passwordsymfony.com'),
163+
array('http://usern@me:password@symfony.com'),
158164
);
159165
}
160166

0 commit comments

Comments
 (0)