From f82b00c25e268c11ed02e97afc8029fb6b68d862 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 8 Oct 2013 12:28:26 -0400 Subject: [PATCH] Fix content view variable being stomped by send() parameter. The content of send() should only be used if it is a non-empty value. Fixes #4129 --- lib/Cake/Network/Email/CakeEmail.php | 8 ++++++- .../Test/Case/Network/Email/CakeEmailTest.php | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 959017556..cfd941ce5 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1313,6 +1313,9 @@ class CakeEmail { * @return array Wrapped message */ protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) { + if (strlen($message) == 0) { + return array(''); + } $message = str_replace(array("\r\n", "\r"), "\n", $message); $lines = explode("\n", $message); $formatted = array(); @@ -1640,8 +1643,11 @@ class CakeEmail { $layout = false; } - foreach ($types as $type) { + if ($View->get('content') == '') { $View->set('content', $content); + } + + foreach ($types as $type) { $View->hasRendered = false; $View->viewPath = $View->layoutPath = 'Emails' . DS . $type; diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 9fbb8c207..48b37c35f 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -904,6 +904,27 @@ class CakeEmailTest extends CakeTestCase { $this->assertEquals(45, $result['timeout']); } +/** + * Calling send() with no parameters should not overwrite the view variables. + * + * @return void + */ + public function testSendWithNoContentDoesNotOverwriteViewVar() { + $this->CakeEmail->reset(); + $this->CakeEmail->transport('Debug'); + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to('you@cakephp.org'); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->emailFormat('text'); + $this->CakeEmail->template('default'); + $this->CakeEmail->viewVars(array( + 'content' => 'A message to you', + )); + + $result = $this->CakeEmail->send(); + $this->assertContains('A message to you', $result['message']); + } + /** * testSendWithContent method *