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 protocols as argument for URL validation #47843

Merged
merged 2 commits into from
Jul 26, 2023

Conversation

MrMicky-FR
Copy link
Contributor

This is a follow-up of #47770 (see last comment, and also #47381), hopefully this is the right one 😃


This PR makes it possible to specify which protocols are allowed in Str::isUrl and in the url validation rule.

This can be useful in two situations:

  • To authorize only some specific protocols (e.g. only https to force secure links)
  • To use exotic protocols that are not in the hardcoded protocols list without having to modify the list directly in Laravel

There is no breaking changes, as the default behavior (when no parameters are used) is the same as current: only the protocols in the existing list are allowed.

Example usage:

$v = Validator::make($data, [
    'url' => 'sometimes|url', // current behavior
    'link' => 'sometimes|url:http,https', // only http and https
    'game_url' => 'sometimes|url:minecraft,steam', // also support more protocols such as 'minecraft://'
]);

Also I think that reducing the default list to only http and https (like Symfony, or even just https to force secure links) might be a sensible option, as most of the times a HTTP(S) URL would be expected, but this would be a breaking change for master in a separate PR.

@taylorotwell taylorotwell merged commit e49896e into laravel:10.x Jul 26, 2023
16 checks passed
@MrMicky-FR MrMicky-FR deleted the is_url_protocols branch July 26, 2023 18:45
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.

None yet

2 participants