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

Skip to content

Commit 382cde2

Browse files
bug #43876 [Validator] Fix validation for single level domains (HypeMC)
This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Fix validation for single level domains | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #43868, #44252 | License | MIT | Doc PR | - Not sure if there are any other test cases that could be added, but this seems to fix the problem. Commits ------- 653a21d [Validator] Fix validation for single level domains
2 parents f3be043 + 653a21d commit 382cde2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines 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

Lines 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://:[email protected]'],
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)