From db2fe55ea682af5f01cedcd8428494152abca7ec Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Wed, 24 Mar 2021 02:36:46 -0600 Subject: [PATCH] fix: handle null values on the password validator (#100) --- src/Rules/Password.php | 3 +++ tests/Rules/PasswordTest.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/Rules/Password.php b/src/Rules/Password.php index 05783c43..296215cb 100644 --- a/src/Rules/Password.php +++ b/src/Rules/Password.php @@ -26,6 +26,9 @@ class Password extends Fortify */ public function passes($attribute, $value) { + // Handle potential NULL values + $value = $value ?: ''; + if ($this->needsLowercase($value)) { return false; } diff --git a/tests/Rules/PasswordTest.php b/tests/Rules/PasswordTest.php index cbc83c34..e2faff7c 100644 --- a/tests/Rules/PasswordTest.php +++ b/tests/Rules/PasswordTest.php @@ -4,6 +4,12 @@ use ARKEcosystem\Fortify\Rules\Password; +it('handle null values', function () { + $rule = (new Password())->requireUppercase()->requireNumeric()->requireSpecialCharacter(); + + expect($rule->passes('password', null))->toBeFalse(); +}); + it('can check for lowercase requirements', function () { $rule = (new Password())->requireLowercase();