Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 829372b

Browse files
committed
[Validator] Fix validation for single level domains
1 parent f86c557 commit 829372b

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class UrlValidator extends ConstraintValidator
2626
(%s):// # protocol
2727
(((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+)@)? # basic auth
2828
(
29-
([\pL\pN\pS\-\_]+\.)*(([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
29+
(
30+
([\pL\pN\pS\-\_]+\.)*([\pL\pN\-\_]+[\pL\pN]\.?) # a multi-level domain name
31+
|
32+
[\pL\pN\pS\-\_]+\.? # a single-level domain name
33+
)
3034
| # or
3135
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
3236
| # or

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public function getValidUrls()
128128
['http://very.long.domain.name.com/'],
129129
['http://localhost/'],
130130
['http://myhost123/'],
131+
['http://internal-api'],
132+
['http://internal-api.'],
133+
['http://internal-api/'],
134+
['http://☎'],
135+
['http://☎.'],
136+
['http://☎/'],
131137
['http://127.0.0.1/'],
132138
['http://127.0.0.1:80/'],
133139
['http://[::1]/'],
@@ -259,6 +265,8 @@ public function getInvalidUrls()
259265
['http://127.0.0.1:aa/'],
260266
['ftp://[::1]/'],
261267
['http://[::1'],
268+
['http://hello.☎'],
269+
['http://hello.☎.'],
262270
['http://hello.☎/'],
263271
['http://:[email protected]'],
264272
['http://:password@@symfony.com'],
@@ -276,6 +284,8 @@ public function getInvalidUrls()
276284
['http://.m.example.com'],
277285
['http://wwww.example..com'],
278286
['http://.www.example.com'],
287+
['http://example.co-'],
288+
['http:///path'],
279289
];
280290
}
281291

0 commit comments

Comments
 (0)