mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
105f032e81
commit
f82b00c25e
2 changed files with 28 additions and 1 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue