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] Add new URI Rule to validate URI and use it to RedirectRule. #1544

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Http/Rules/RedirectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Validation\Factory;
use Illuminate\Contracts\Validation\Rule;
use Laravel\Passport\Http\Rules\UriRule;

class RedirectRule implements Rule
{
Expand Down Expand Up @@ -31,7 +32,7 @@ public function __construct(Factory $validator)
public function passes($attribute, $value)
{
foreach (explode(',', $value) as $redirect) {
$validator = $this->validator->make(['redirect' => $redirect], ['redirect' => 'url']);
$validator = $this->validator->make(['redirect' => $redirect], ['redirect' => new UriRule]);

if ($validator->fails()) {
return false;
Expand All @@ -46,6 +47,6 @@ public function passes($attribute, $value)
*/
public function message()
{
return 'One or more redirects have an invalid url format.';
return 'One or more redirects have an invalid URI format.';
}
}
28 changes: 28 additions & 0 deletions src/Http/Rules/UriRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Laravel\Passport\Http\Rules;

use Illuminate\Contracts\Validation\Rule;

class UriRule implements Rule
{
/**
* {@inheritdoc}
*/
public function passes($attribute, $value): bool
{
if (filter_var($value, FILTER_VALIDATE_URL)) {
return true;
}

return false;
}

/**
* {@inheritdoc}
*/
public function message(): string
{
return 'The :attribute must be valid URI.';
}
}