Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit f82b00c25e268c11ed02e97afc8029fb6b68d862 1 parent 105f032
@markstory markstory authored
View
8 lib/Cake/Network/Email/CakeEmail.php
@@ -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) {
@dereuromark Collaborator

I'd prefer === . But that's just me :dancer:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return array('');
+ }
$message = str_replace(array("\r\n", "\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
@@ -1640,8 +1643,11 @@ protected function _renderTemplates($content) {
$layout = false;
}
- foreach ($types as $type) {
+ if ($View->get('content') == '') {
@dereuromark Collaborator

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

@markstory Owner

Good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
$View->set('content', $content);
+ }
+
+ foreach ($types as $type) {
$View->hasRendered = false;
$View->viewPath = $View->layoutPath = 'Emails' . DS . $type;
View
21 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -905,6 +905,27 @@ public function testConfigMerge() {
}
/**
+ * 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
*
* @return void

1 comment on commit f82b00c

@davidyell

Thanks! :+1:

Please sign in to comment.
Something went wrong with that request. Please try again.