Skip to content

Commit 86dd9ad

Browse files
battyenicolas-grekas
authored andcommitted
[Validator] Accept underscores in the URL validator as the URL will resolve correctly
1 parent 082eb13 commit 86dd9ad

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

Tests/Constraints/UrlValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function getValidUrls()
7272
['http://www.example.museum'],
7373
['https://example.com/'],
7474
['https://example.com:80/'],
75+
['http://examp_le.com'],
76+
['http://www.sub_domain.examp_le.com'],
7577
['http://www.example.coop/'],
7678
['http://www.test-example.com/'],
7779
['http://www.symfony.com/'],
@@ -152,7 +154,6 @@ public function getInvalidUrls()
152154
['://example.com'],
153155
['http ://example.com'],
154156
['http:/example.com'],
155-
['http://examp_le.com'],
156157
['http://example.com::aa'],
157158
['http://example.com:aa'],
158159
['ftp://example.fr'],

0 commit comments

Comments
 (0)