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

Skip to content

[Validator] After update to 5.3.10 before valid urls are now marked as invalid #43868

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

Closed
MiroCillik opened this issue Nov 1, 2021 · 7 comments

Comments

@MiroCillik
Copy link

MiroCillik commented Nov 1, 2021

Symfony version(s) affected

5.3.10

Description

After update to symfony/validator 5.3.10 #43388 the Url Validator marks urls like http://internal-api as invalid. This url was fine in version 5.3.8 and the PR seems to be fixing a different issue, so it seems like unwanted consequence. The hyphen seems to be the problem. Urls like this one are commonly used for docker-compose services.

How to reproduce

$validator = Symfony\Component\Validator\Validation::createValidator();
$errors = $validator->validate('http://internal-api', [new Url()]);
var_dump($errors);

Possible Solution

No response

Additional Context

No response

@derrabus
Copy link
Member

derrabus commented Nov 1, 2021

Confirmed. @DfKimera, can you have a look please?

@valkars
Copy link

valkars commented Nov 1, 2021

We have another issue, after update urls http://a, http://aa marked as valid, they were invalid earlier, our tests are broken now. This commit I think:
27b1153

@derrabus
Copy link
Member

derrabus commented Nov 1, 2021

after update urls http://a, http://aa marked as valid, they were invalid earlier

Yes, this is the problem that #43388 attempted to solve. Those two URLs of yours are valid URLs, aren't they?

@valkars
Copy link

valkars commented Nov 1, 2021

They don't have a domain part and any reserved word (localhost), so they are invalid, am I wrong?

@derrabus
Copy link
Member

derrabus commented Nov 1, 2021

They don't have a domain part

They don't need to. a is a valid hostname. If you want to try it out for yourself, edit your /etc/hosts file and bind a to a valid IP address (e.g. 127.0.0.1). Your browser will happily open http://a if a web server listens on the machine that belongs to that IP address.

As mentioned by @MiroCillik, hostnames without a domain part are common in Docker setups.

@valkars
Copy link

valkars commented Nov 1, 2021

So we have form with company url and now user can enter http://a, useless validator, thanks for this "feature".

@derrabus
Copy link
Member

derrabus commented Nov 1, 2021

So we have form with company url and now user can enter http://a, useless validator, thanks for this "feature".

Before the change, the user could enter http://a-a or http://localhost to pass validation. The Url constraint has never checked if the URL contained a top level domain.

pepamartinec added a commit to keboola/sandboxes-api-php-client that referenced this issue Nov 12, 2021
nicolas-grekas added a commit that referenced this issue Nov 29, 2021
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
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