Skip to content

Commit

Permalink
Fix content view variable being stomped by send() parameter.
Browse files Browse the repository at this point in the history
The content of send() should only be used if it is a non-empty value.

Fixes #4129
  • Loading branch information
markstory committed Oct 8, 2013
1 parent 105f032 commit f82b00c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1313,6 +1313,9 @@ protected function _encodeString($text, $charset) {
* @return array Wrapped message
*/
protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) {
if (strlen($message) == 0) {

This comment has been minimized.

Copy link
@dereuromark

dereuromark Oct 8, 2013

Member

I'd prefer === . But that's just me 💃

return array('');
}
$message = str_replace(array("\r\n", "\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
Expand Down Expand Up @@ -1640,8 +1643,11 @@ protected function _renderTemplates($content) {
$layout = false;
}

foreach ($types as $type) {
if ($View->get('content') == '') {

This comment has been minimized.

Copy link
@dereuromark

dereuromark Oct 8, 2013

Member

Maybe if (!$View->get('content')) as it also matches numeric 0 and null etc? Or === null as it should return null as default.

This comment has been minimized.

Copy link
@markstory

markstory Oct 8, 2013

Author Member

Good point.

$View->set('content', $content);
}

foreach ($types as $type) {
$View->hasRendered = false;
$View->viewPath = $View->layoutPath = 'Emails' . DS . $type;

Expand Down
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -904,6 +904,27 @@ public function testConfigMerge() {
$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
*
Expand Down

1 comment on commit f82b00c

@davidyell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

Please sign in to comment.