From 8c3982b192a927414c5f6f6e21dd5bc4f4f04383 Mon Sep 17 00:00:00 2001 From: AlexAlexandru Date: Wed, 1 Aug 2018 20:54:53 +0300 Subject: [PATCH 1/3] fixes #11424 Enchament to email class error message --- lib/Cake/Network/Email/CakeEmail.php | 18 +++++++------ .../Test/Case/Network/Email/CakeEmailTest.php | 25 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 174301415..4b5c838df 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -589,7 +589,7 @@ class CakeEmail { */ protected function _setEmail($varName, $email, $name) { if (!is_array($email)) { - $this->_validateEmail($email); + $this->_validateEmail($email, $varName); if ($name === null) { $name = $email; } @@ -601,7 +601,7 @@ class CakeEmail { if (is_int($key)) { $key = $value; } - $this->_validateEmail($key); + $this->_validateEmail($key, $varName); $list[$key] = $value; } $this->{$varName} = $list; @@ -611,11 +611,12 @@ class CakeEmail { /** * Validate email address * - * @param string $email Email + * @param string $email Email address to validate + * @param string $context Which property was set * @return void * @throws SocketException If email address does not validate */ - protected function _validateEmail($email) { + protected function _validateEmail($email, $context) { if ($this->_emailPattern === null) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { return; @@ -623,7 +624,10 @@ class CakeEmail { } elseif (preg_match($this->_emailPattern, $email)) { return; } - throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $email)); + if ($email == '') { + throw new SocketException(__d('cake_dev', 'The email set for "%s" is empty.', $context)); + } + throw new SocketException(__d('cake_dev', 'Invalid email set for "%s". You passed "%s".', $context, $email)); } /** @@ -659,7 +663,7 @@ class CakeEmail { */ protected function _addEmail($varName, $email, $name) { if (!is_array($email)) { - $this->_validateEmail($email); + $this->_validateEmail($email, $varName); if ($name === null) { $name = $email; } @@ -671,7 +675,7 @@ class CakeEmail { if (is_int($key)) { $key = $value; } - $this->_validateEmail($key); + $this->_validateEmail($key, $varName); $list[$key] = $value; } $this->{$varName} = array_merge($this->{$varName}, $list); diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index a0d15bec8..d0f018de3 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -334,23 +334,34 @@ class CakeEmailTest extends CakeTestCase { /** * testBuildInvalidData * - * @dataProvider invalidEmails * @expectedException SocketException + * @expectedExceptionMessage The email set for "_to" is empty. * @return void */ - public function testInvalidEmail($value) { - $this->CakeEmail->to($value); + public function testInvalidEmail() { + $this->CakeEmail->to(''); + } + +/** + * testBuildInvalidData + * + * @expectedException SocketException + * @expectedExceptionMessage Invalid email set for "_from". You passed "cake.@" + * @return void + */ + public function testInvalidFrom() { + $this->CakeEmail->from('cake.@'); } /** * testBuildInvalidData * - * @dataProvider invalidEmails * @expectedException SocketException + * @expectedExceptionMessage Invalid email set for "_to". You passed "1" * @return void */ - public function testInvalidEmailAdd($value) { - $this->CakeEmail->addTo($value); + public function testInvalidEmailAdd() { + $this->CakeEmail->addTo('1'); } /** @@ -423,7 +434,7 @@ class CakeEmailTest extends CakeTestCase { * @return void * * @expectedException SocketException - * @expectedExceptionMessage Invalid email: "fail.@example.com" + * @expectedExceptionMessage Invalid email set for "_to". You passed "fail.@example.com" */ public function testUnsetEmailPattern() { $email = new CakeEmail(); From 44c0d733912a1e83dd5badc332a4bc9caa232bf3 Mon Sep 17 00:00:00 2001 From: AlexAlexandru Date: Wed, 1 Aug 2018 21:04:50 +0300 Subject: [PATCH 2/3] code style --- lib/Cake/Network/Email/CakeEmail.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 4b5c838df..997760baa 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -624,10 +624,10 @@ class CakeEmail { } elseif (preg_match($this->_emailPattern, $email)) { return; } - if ($email == '') { - throw new SocketException(__d('cake_dev', 'The email set for "%s" is empty.', $context)); + if ($email == '') { + throw new SocketException(__d('cake_dev', 'The email set for "%s" is empty.', $context)); } - throw new SocketException(__d('cake_dev', 'Invalid email set for "%s". You passed "%s".', $context, $email)); + throw new SocketException(__d('cake_dev', 'Invalid email set for "%s". You passed "%s".', $context, $email)); } /** From c44113af66597fdd60b0c98a8d6c711429f52291 Mon Sep 17 00:00:00 2001 From: AlexAlexandru Date: Wed, 1 Aug 2018 21:50:38 +0300 Subject: [PATCH 3/3] code style --- lib/Cake/Network/Email/CakeEmail.php | 2 +- lib/Cake/Test/Case/Network/Email/CakeEmailTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 997760baa..ee4da73d9 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -626,7 +626,7 @@ class CakeEmail { } if ($email == '') { throw new SocketException(__d('cake_dev', 'The email set for "%s" is empty.', $context)); - } + } throw new SocketException(__d('cake_dev', 'Invalid email set for "%s". You passed "%s".', $context, $email)); } diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index d0f018de3..ca7ae2a38 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -341,7 +341,7 @@ class CakeEmailTest extends CakeTestCase { public function testInvalidEmail() { $this->CakeEmail->to(''); } - + /** * testBuildInvalidData *