diff --git a/src/Network/Email/Email.php b/src/Network/Email/Email.php index ccc3fe19663..9545e48567d 100644 --- a/src/Network/Email/Email.php +++ b/src/Network/Email/Email.php @@ -579,11 +579,13 @@ public function headerCharset($charset = null) { /** * EmailPattern setter/getter * - * @param string $regex for email address validation + * @param string|bool|null $regex The pattern to use for email address validation, + * null to unset the pattern and make use of filter_var() instead, false or + * nothing to return the current value * @return string|$this */ - public function emailPattern($regex = null) { - if ($regex === null) { + public function emailPattern($regex = false) { + if ($regex === false) { return $this->_emailPattern; } $this->_emailPattern = $regex; @@ -629,10 +631,11 @@ protected function _setEmail($varName, $email, $name) { * @throws \InvalidArgumentException If email address does not validate */ protected function _validateEmail($email) { - if ($this->_emailPattern === null && filter_var($email, FILTER_VALIDATE_EMAIL)) { - return; - } - if (preg_match($this->_emailPattern, $email)) { + if ($this->_emailPattern === null) { + if (filter_var($email, FILTER_VALIDATE_EMAIL)) { + return; + } + } elseif (preg_match($this->_emailPattern, $email)) { return; } throw new InvalidArgumentException(sprintf('Invalid email: "%s"', $email)); diff --git a/src/Network/Session/CacheSession.php b/src/Network/Session/CacheSession.php index 7b93eea8568..472a42a349f 100644 --- a/src/Network/Session/CacheSession.php +++ b/src/Network/Session/CacheSession.php @@ -104,10 +104,11 @@ public function destroy($id) { * Helper function called on gc for cache sessions. * * @param string $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed. - * @return void + * @return bool True (irrespective of whether or not the garbage is being successfully collected) */ public function gc($maxlifetime) { Cache::gc($this->_options['config'], time() - $maxlifetime); + return true; } } diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 73a8bccbab4..5d11f07a8f7 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -138,7 +138,7 @@ public function render($view = null, $layout = null) { /** * Serialize view vars * - * @param array|string $serialize The viewVars that need to be serialized + * @param array|string $serialize The name(s) of the view variable(s) that need(s) to be serialized * @return string The serialized data */ protected function _serialize($serialize) { diff --git a/src/View/XmlView.php b/src/View/XmlView.php index 9bd1682f25f..48277636f4c 100644 --- a/src/View/XmlView.php +++ b/src/View/XmlView.php @@ -122,7 +122,7 @@ public function render($view = null, $layout = null) { /** * Serialize view vars. * - * @param array|string $serialize The viewVars that need to be serialized. + * @param array|string $serialize The name(s) of the view variable(s) that need(s) to be serialized * @return string The serialized data */ protected function _serialize($serialize) { diff --git a/tests/TestCase/Network/Email/EmailTest.php b/tests/TestCase/Network/Email/EmailTest.php index 4840474a540..18ddc36aaa1 100644 --- a/tests/TestCase/Network/Email/EmailTest.php +++ b/tests/TestCase/Network/Email/EmailTest.php @@ -333,6 +333,25 @@ public function testCustomEmailValidation() { ), $this->CakeEmail->to()); } +/** + * Tests that it is possible to unset the email pattern and make use of filter_var() instead. + * + * @return void + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid email: "fail.@example.com" + */ + public function testUnsetEmailPattern() { + $email = new Email(); + $this->assertSame(Email::EMAIL_PATTERN, $email->emailPattern()); + + $email->emailPattern(null); + $this->assertNull($email->emailPattern()); + + $email->to('pass@example.com'); + $email->to('fail.@example.com'); + } + /** * testFormatAddress method *