Skip to content

[Validator] : fix url validation when punycode is on tld but not on domain #60124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Symfony/Component/Validator/Constraints/UrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ class UrlValidator extends ConstraintValidator
(((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+)@)? # basic auth
(
(?:
(?:xn--[a-z0-9-]++\.)*+xn--[a-z0-9-]++ # a domain name using punycode
|
(?:[\pL\pN\pS\pM\-\_]++\.)+[\pL\pN\pM]++ # a multi-level domain name
(?:
(?:[\pL\pN\pS\pM\-\_]++\.)+
(?:
(?:xn--[a-z0-9-]++) # punycode in tld
|
(?:[\pL\pN\pM]++) # no punycode in tld
)
) # a multi-level domain name
|
[a-z0-9\-\_]++ # a single-level domain name
)\.?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public static function getValidUrls()
['http://xn--e1afmkfd.xn--80akhbyknj4f.xn--e1afmkfd/'],
['http://xn--espaa-rta.xn--ca-ol-fsay5a/'],
['http://xn--d1abbgf6aiiy.xn--p1ai/'],
['http://example.xn--p1ai/'],
['http://xn--d1abbgf6aiiy.example.xn--p1ai/'],
['http://☎.com/'],
['http://username:password@symfony.com'],
['http://user.name:password@symfony.com'],
Expand Down
Loading