Skip to content

Commit 13db415

Browse files
Benjamin Laugueuxfabpot
authored andcommitted
Allow basic auth in url. Improve regex. Add tests.
1 parent 599f802 commit 13db415

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

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:[email protected]'),
120+
array('http://[email protected]'),
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://:[email protected]'),
161+
array('http://:password@@symfony.com'),
162+
array('http://username:passwordsymfony.com'),
163+
array('http://usern@me:[email protected]'),
158164
);
159165
}
160166

0 commit comments

Comments
 (0)