Skip to content
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

[Url validator] Returns false for valid (and existing) url #32506

Closed
kptLucek opened this issue Jul 12, 2019 · 3 comments
Closed

[Url validator] Returns false for valid (and existing) url #32506

kptLucek opened this issue Jul 12, 2019 · 3 comments

Comments

@kptLucek
Copy link

kptLucek commented Jul 12, 2019

Symfony version(s) affected: 4.3.2 (propably earlier versions too)

Description
Url validator returns false (invalid url) on valid, and existing url - pattern issue

How to reproduce
Simply get an validator instance, and validate string/model with Url validator.
Url must contain underscores _ (im amazed to see them in url tho)

$url        = 'http://www.cku_zsr_glubczyce.wodip.opole.pl';
$violations = $this->validator->validate(['url' => $url], [
    new Collection([
        'fields' => [
            'url' => [new Url()]
        ]
    ])
]);
if ($violations->count() > 0) {
/** @var ConstraintViolation $violation */
foreach ($violations as $violation) {
    echo $violation->getPropertyPath() . ' :: ' . $violation->getMessage() . "\n";
}

Possible Solution
Update pattern in validator :)

Additional context

@Tobion
Copy link
Contributor

Tobion commented Jul 12, 2019

@kptLucek
Copy link
Author

@Tobion what do you mean?

The url i have provided is a string i want to validate, i have service that does collect alot of data by school-type facilities, and url (like one above) is one of properties i do collect.

Everything is verified, and given url is valid, exists, and may be visited (GET to this url returns valid 200 HTTP response).

All i need is to verify if given "string" is "url" (which should be done by Url validator, but is not in given case).

Link from above shows that subdomain(s) with underscore (_) in their name are very common, however for those validator returns violation.

@javiereguiluz
Copy link
Member

javiereguiluz commented Jul 12, 2019

There are several things to consider:

@fabpot fabpot closed this as completed Sep 27, 2019
fabpot added a commit that referenced this issue Sep 27, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants