Skip to content

Commit 1225c80

Browse files
authored
Merge pull request #723 from GeorgKott/fix_nothing_personal_validator_error
fix: nothing personal validator error with bad email value
2 parents 0ceb817 + 57f35b9 commit 1225c80

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

src/Authentication/Passwords/NothingPersonalValidator.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ protected function isNotPersonal(string $password, ?User $user): bool
7272
$needles = $this->strip_explode($userName);
7373

7474
// extract local-part and domain parts from email as separate needles
75-
[
76-
$localPart,
77-
$domain,
78-
] = explode('@', $email);
75+
if (str_contains($email, '@')) {
76+
[
77+
$localPart,
78+
$domain,
79+
] = explode('@', $email);
80+
} else {
81+
$localPart = $email;
82+
$domain = null;
83+
}
7984
// might be [email protected] and we want all the needles we can get
8085
$emailParts = $this->strip_explode($localPart);
8186
if (! empty($domain)) {

tests/Controllers/RegisterTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,24 @@ public function testRegisterActionRedirectsIfLoggedIn(): void
294294
$result->assertRedirectTo(config('Auth')->registerRedirect());
295295
}
296296

297+
public function testRegisterActionWithBadEmailValue(): void
298+
{
299+
$result = $this->withSession()->post('/register', [
300+
'username' => 'JohnDoe',
301+
'email' => 'john.doe',
302+
'password' => '123456789aa',
303+
'password_confirm' => '123456789aa',
304+
]);
305+
306+
$result->assertStatus(302);
307+
$result->assertRedirect();
308+
$result->assertSessionMissing('error');
309+
$result->assertSessionHas(
310+
'errors',
311+
['email' => 'The Email Address field must contain a valid email address.']
312+
);
313+
}
314+
297315
protected function setupConfig(): void
298316
{
299317
$config = config('Validation');

tests/Unit/NothingPersonalValidatorTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,41 @@ public static function maxSimilarityProvider()
287287
],
288288
];
289289
}
290+
291+
/**
292+
* @dataProvider badEmailsProvider
293+
*/
294+
public function testCheckPasswordWithBadEmail(string $email, bool $expected): void
295+
{
296+
$config = new Auth();
297+
$this->validator = new NothingPersonalValidator($config);
298+
299+
$user = new User([
300+
'username' => 'CaptainJoe',
301+
'email' => $email,
302+
]);
303+
304+
$password = '123456789a';
305+
306+
$result = $this->validator->check($password, $user);
307+
308+
$this->assertSame($expected, $result->isOK());
309+
}
310+
311+
public static function badEmailsProvider()
312+
{
313+
return [
314+
[
315+
'test',
316+
true,
317+
], [
318+
'test@example',
319+
true,
320+
],
321+
[
322+
323+
true,
324+
],
325+
];
326+
}
290327
}

0 commit comments

Comments
 (0)