Option 2: check if the value is a string in the Password rule class (it's a direct copy of the string rule). I'd be happy to put this in a PR if you'd like to go this route.
public function passes($attribute, $value)
{
if(! is_string($value)) { // add this condition
return false;
}
if ($this->requireUppercase && Str::lower($value) === $value) {
return false;
}
if ($this->requireNumeric && ! preg_match('/[0-9]/', $value)) {
return false;
}
if ($this->requireSpecialCharacter && ! preg_match('/[\W_]/', $value)) {
return false;
}
return Str::length($value) >= $this->length;
}
Description:
When providing a non-scalar input for the password field (e.g. an array), the Password rule will throw an exception for
mb_*
andpreg_match
functions:requireUppercase
)requireNumeric
andrequireSpecialCharacter
)Steps To Reproduce:
Exception:
Possible solutions:
Option 1: add
bail
before the Password ruleOption 2: check if the value is a string in the Password rule class (it's a direct copy of the
string
rule). I'd be happy to put this in a PR if you'd like to go this route.