-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Accept underscores in the URL validator, as the URL will load #32522
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
Conversation
src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
Outdated
Show resolved
Hide resolved
Review found that this should not be allowed in the root domain name.
One important thing to consider is that it will be quite difficult to determine what constitutes a subdomain and what constitutes a root domain. Consider Given that this class is symfony/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php Lines 89 to 90 in 66e2cb6
As we already validate hostnames as Maybe a new domain validator would be a good feature though? I think having a domain validator is really the only way we can solve this problem in its entirety though, as a regex-only solution looks to be unfeasible. With a domain validator, we could maintain a list of known TLDs and fixed second-level domains. Perhaps it could allow for an integration with the URL validator, with an option of specifying a URL as belonging to a hostname or domain name before validating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me, this is pragmatic enough.
66e2cb6
to
07cbe94
Compare
src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
Outdated
Show resolved
Hide resolved
07cbe94
to
c9c7a11
Compare
Thank you @battye. |
…e URL will load (battye) This PR was merged into the 3.4 branch. Discussion ---------- [Validator] Accept underscores in the URL validator, as the URL will load | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32506 | License | MIT | Doc PR | - As @javiereguiluz mentioned, regardless of convention a URL with an underscore in it will load perfectly fine - so in that respect it must be valid. Commits ------- c9c7a11 [Validator] Accept underscores in the URL validator as the URL will resolve correctly
It should be an opt-in option. Unlike domain names, hostnames (and so URLs) cannot contain underscores (RFC 1123, section 2.1). While it’s ok to support this for compatibility with non-standard clients, but it shouldn’t be the default. |
Also, PHP has a built-in domain name validator (you’re right, a domain name cannot be validated with a regex). |
As @javiereguiluz mentioned, regardless of convention a URL with an underscore in it will load perfectly fine - so in that respect it must be valid.