Fixed RB-4138 - json validation on wonky params
This commit is contained in:
@@ -4,17 +4,18 @@ namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Translation\PotentiallyTranslatedString;
|
||||
|
||||
class ValidJson implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @param Closure(string, ?string=): PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (!json_validate($value)) {
|
||||
if (! is_string($value) || ! json_validate($value)) {
|
||||
$fail(trans('validation.json'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user