Browse Source

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
mark_story 12 years ago
parent
commit
f82b00c25e

+ 7 - 1
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;
 

+ 21 - 0
lib/Cake/Test/Case/Network/Email/CakeEmailTest.php

@@ -905,6 +905,27 @@ class CakeEmailTest extends CakeTestCase {
 	}
 
 /**
+ * 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