Skip to content

Commit 5a992f1

Browse files
committed
fix(validator): only check for puny code in tld
1 parent 9314555 commit 5a992f1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Constraints/UrlValidator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ class UrlValidator extends ConstraintValidator
2626
(((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+)@)? # basic auth
2727
(
2828
(?:
29-
(?:xn--[a-z0-9-]++\.)*+xn--[a-z0-9-]++ # a domain name using punycode
30-
|
31-
(?:[\pL\pN\pS\pM\-\_]++\.)+[\pL\pN\pM]++ # a multi-level domain name
29+
(?:
30+
(?:[\pL\pN\pS\pM\-\_]++\.)+
31+
(?:
32+
(?:xn--[a-z0-9-]++) # punycode in tld
33+
|
34+
(?:[\pL\pN\pM]++) # no punycode in tld
35+
)
36+
) # a multi-level domain name
3237
|
3338
[a-z0-9\-\_]++ # a single-level domain name
3439
)\.?

Tests/Constraints/UrlValidatorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ public static function getValidUrls()
186186
['http://xn--e1afmkfd.xn--80akhbyknj4f.xn--e1afmkfd/'],
187187
['http://xn--espaa-rta.xn--ca-ol-fsay5a/'],
188188
['http://xn--d1abbgf6aiiy.xn--p1ai/'],
189+
['http://example.xn--p1ai/'],
190+
['http://xn--d1abbgf6aiiy.example.xn--p1ai/'],
189191
['http://☎.com/'],
190192
['http://username:[email protected]'],
191193
['http://user.name:[email protected]'],

0 commit comments

Comments
 (0)