Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 653a21d

Browse filesBrowse files
HypeMCnicolas-grekas
authored andcommitted
[Validator] Fix validation for single level domains
1 parent f86c557 commit 653a21d
Copy full SHA for 653a21d

File tree

Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/UrlValidator.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ 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+
(?:xn--[a-z0-9-]++\.)*+xn--[a-z0-9-]++ # a domain name using punycode
31+
|
32+
(?:[\pL\pN\pS\pM\-\_]++\.)+[\pL\pN\pM]++ # a multi-level domain name
33+
|
34+
[a-z0-9\-\_]++ # a single-level domain name
35+
)\.?
3036
| # or
3137
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
3238
| # or

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ 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://internal-api/path'],
131135
['http://127.0.0.1/'],
132136
['http://127.0.0.1:80/'],
133137
['http://[::1]/'],
@@ -174,6 +178,7 @@ public function getValidUrls()
174178
['http://symfony.com/#fragment'],
175179
['http://symfony.com/#one_more%20test'],
176180
['http://example.com/exploit.html?hello[0]=test'],
181+
['http://বিডিআইএ.বাংলা'],
177182
];
178183
}
179184

@@ -259,7 +264,14 @@ public function getInvalidUrls()
259264
['http://127.0.0.1:aa/'],
260265
['ftp://[::1]/'],
261266
['http://[::1'],
267+
['http://☎'],
268+
['http://☎.'],
269+
['http://☎/'],
270+
['http://☎/path'],
271+
['http://hello.☎'],
272+
['http://hello.☎.'],
262273
['http://hello.☎/'],
274+
['http://hello.☎/path'],
263275
['http://:password@symfony.com'],
264276
['http://:password@@symfony.com'],
265277
['http://username:passwordsymfony.com'],
@@ -276,6 +288,9 @@ public function getInvalidUrls()
276288
['http://.m.example.com'],
277289
['http://wwww.example..com'],
278290
['http://.www.example.com'],
291+
['http://example.co-'],
292+
['http://example.co-/path'],
293+
['http:///path'],
279294
];
280295
}
281296

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.