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

[10.x] Accept minecraft protocol in URL validation #47770

Closed
wants to merge 1 commit into from

Conversation

MrMicky-FR
Copy link
Contributor

This adds support for the minecraft protocol in Str::isUrl and the url validation rule. This protocol is a valid URL protocol used by the Minecraft game to join a Minecraft server (same idea as the steam protocol, which is already in the list).

I had submitted a PR to be able to specify new protocols without having to modify this insane protocols list (#47381) but unfortunately it was closed and my latest comment is still unanswered after one month 😕

Copy link
Member

@GrahamCampbell GrahamCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 We should not diverge from the Symfony list. If we need something adding, it should be added to Symfony first.

@MrMicky-FR
Copy link
Contributor Author

MrMicky-FR commented Jul 18, 2023

👎 We should not diverge from the Symfony list. If we need something adding, it should be added to Symfony first.

@GrahamCampbell From what I can tell, Symfony doesn't include this list as the protocols are user-defined (which is more flexible): https://github.com/symfony/symfony/blob/v6.3.1/src/Symfony/Component/Validator/Constraints/UrlValidator.php#L25

And the default protocols only contains http and https:
https://github.com/symfony/symfony/blob/v6.3.1/src/Symfony/Component/Validator/Constraints/Url.php#L38

@henzeb
Copy link
Contributor

henzeb commented Jul 18, 2023

Then we need a way to add protocols the application accepts, instead of adding protocols to laravel as we go. As it may very well be that I need it to be https, but some idiot passed Minecraft url and now my app breaks if I do not add a regex to validate it starts with http...

As far as I can tell, the url validation is basically useless IMHO.

@MrMicky-FR
Copy link
Contributor Author

As it may very well be that I need it to be https, but some idiot passed Minecraft url and now my app breaks if I do not add a regex to validate it starts with http...

As Taylor Otwell suggested, you can use url|starts_with:http,https, but I also think the best solution would be to completly remove this list.

Then we need a way to add protocols the application accepts, instead of adding protocols to laravel as we go.

I agree with you, especially as many protocols in this list doesn't make sense. I would be happy to do a new PR for a different approach to solve this, I'm just not sure how to do it, as my last attempt (#47381) was closed.

@henriquecm
Copy link

I think the best approach would be having a short list with the most commonly used protocols ex: http,https, ftp, ssh, mailto, tel, blob, etc.

And a configuration for other accepted protocol at application level, similar to how you can configure default string size for migrations Schema::defaultStringLength().

$default = Str::$defaultAcceptedProtocols;
Str::defaultAcceptedProtocols([...$default, 'minecraft']);

And a optional argument on Str::isUrl that is merged with the default list.

@henzeb
Copy link
Contributor

henzeb commented Jul 19, 2023

I think the best approach would be having a short list with the most commonly used protocols ex: http,https, ftp, ssh, mailto, tel, blob, etc.

And a configuration for other accepted protocol at application level, similar to how you can configure default string size for migrations Schema::defaultStringLength().

Still no. I think we need something that allows you to specify the protocols your application accepts for that specific field. I can't think of a common use case where an url can be any of those, as your application, frontend or backend, needs to be able to handle them. Most of the time you want to register the website of a user. The user wants a Minecraft url, he is probably not planning to allow mailto or tel there. Simply http/https would be a default situation. anything else is for specific use cases.

@taylorotwell
Copy link
Member

@MrMicky-FR let's actually just revisit your original PR: #47381

Can you reopen it?

@MrMicky-FR MrMicky-FR deleted the minecraft_isurl_protocol branch July 24, 2023 15:41
@MrMicky-FR
Copy link
Contributor Author

@MrMicky-FR let's actually just revisit your original PR: #47381

Can you reopen it?

Seems like I can’t reopen a PR that I haven’t closed myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants