[13.x] Prevent TypeError in Validator::validateDistinct()

Merged
TH
3mo ago
+4-1

Fixes a Fatal TypeError when using distinct:ignore_case on nested wildcards where the attribute value is non-string.

Problem

Validator::validateDistinct() calls preg_quote($value, '/') directly whenever ignore_case is present in parameters. When validating nested attributes like users.*.name where the value resolves to an array, preg_quote() throws a TypeError.

Reproduction

$validator = new Validator(app('translator'), [
    'users' => [['name' => ['John']], ['name' => ['john']]],
], ['users.*.name' => 'distinct:ignore_case']);

$validator->passes();
// Throws TypeError: preg_quote(): Argument #1 ($str) must be of type string, array given

Solution

Added an is_string($value) check to the ignore_case conditional so non-string values safely fall through to standard in_array() validation instead of crashing preg_quote().