diff --git a/app/Models/Contact/Contact.php b/app/Models/Contact/Contact.php index 40fe2d81737..15992130dea 100644 --- a/app/Models/Contact/Contact.php +++ b/app/Models/Contact/Contact.php @@ -994,7 +994,11 @@ public function getGravatar($size) return false; } - if (! app('gravatar')->exists($email)) { + try { + if (! app('gravatar')->exists($email)) { + return false; + } + } catch (\Creativeorange\Gravatar\Exceptions\InvalidEmailException $e) { return false; } diff --git a/tests/Unit/ContactTest.php b/tests/Unit/ContactTest.php index 60b07664a9d..d660f55c56e 100644 --- a/tests/Unit/ContactTest.php +++ b/tests/Unit/ContactTest.php @@ -543,6 +543,23 @@ public function test_gravatar_set_emailnotexists() $this->assertNull($contact->getAvatarURL()); } + public function test_gravatar_set_emailbadformat() + { + $account = factory(Account::class)->create(); + $contact = factory(Contact::class)->create(['account_id' => $account->id]); + $contactFieldType = factory(ContactFieldType::class)->create(['account_id' => $account->id]); + $contactField = factory(ContactField::class)->create([ + 'account_id' => $account->id, + 'contact_id' => $contact->id, + 'contact_field_type_id' => $contactFieldType->id, + 'data' => ' bad%20updateGravatar(); + + $this->assertNull($contact->getAvatarURL()); + } + public function test_gravatar_set_emailreal() { $account = factory(Account::class)->create();