Skip to content

Commit 07cbe94

Browse files
battyenicolas-grekas
authored andcommitted
[Validator] Accept underscores in the URL validator as the URL will resolve correctly
1 parent ad66a16 commit 07cbe94

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UrlValidator extends ConstraintValidator
2525
(%s):// # protocol
2626
(([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth
2727
(
28-
([\pL\pN\pS\-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
28+
([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
2929
| # or
3030
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
3131
| # or

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ public function getValidUrls()
6767
{
6868
return [
6969
['http://a.pl'],
70+
<<<<<<< HEAD
7071
['http://www.example.com'],
7172
['http://www.example.com.'],
7273
['http://www.example.museum'],
7374
['https://example.com/'],
7475
['https://example.com:80/'],
76+
['http://examp_le.com'],
77+
['http://www.sub_domain.examp_le.com'],
7578
['http://www.example.coop/'],
7679
['http://www.test-example.com/'],
7780
['http://www.symfony.com/'],
@@ -148,6 +151,7 @@ public function testInvalidUrls($url)
148151
public function getInvalidUrls()
149152
{
150153
return [
154+
<<<<<<< HEAD
151155
['example.com'],
152156
['://example.com'],
153157
['http ://example.com'],
@@ -157,6 +161,16 @@ public function getInvalidUrls()
157161
['http://example.com:aa'],
158162
['ftp://example.fr'],
159163
['faked://example.fr'],
164+
=======
165+
['google.com'],
166+
['://google.com'],
167+
['http ://google.com'],
168+
['http:/google.com'],
169+
['http://google.com::aa'],
170+
['http://google.com:aa'],
171+
['ftp://google.fr'],
172+
['faked://google.fr'],
173+
>>>>>>> [Validator] Accept underscores in the URL validator as the URL will resolve correctly
160174
['http://127.0.0.1:aa/'],
161175
['ftp://[::1]/'],
162176
['http://[::1'],

0 commit comments

Comments
 (0)