浏览代码

Fix error when wrapping email message content.

Fixes #14459
ADmad 6 年之前
父节点
当前提交
9b0cbc1f30
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 1 1
      src/Mailer/Email.php
  2. 6 0
      tests/TestCase/Mailer/EmailTest.php

+ 1 - 1
src/Mailer/Email.php

@@ -2458,7 +2458,7 @@ class Email implements JsonSerializable, Serializable
                 $tmpLine .= $char;
                 $tmpLineLength++;
                 if ($tmpLineLength === $wrapLength) {
-                    $nextChar = $line[$i + 1];
+                    $nextChar = isset($line[$i + 1]) ? $line[$i + 1] : '';
                     if ($nextChar === ' ' || $nextChar === '<') {
                         $formatted[] = trim($tmpLine);
                         $tmpLine = '';

+ 6 - 0
tests/TestCase/Mailer/EmailTest.php

@@ -2868,6 +2868,12 @@ class EmailTest extends TestCase
         $expected = $str1 . str_repeat('x', Email::LINE_LENGTH_MUST - $length + 1) . sprintf("\r\n%s\r\n\r\n", trim($str2));
         $this->assertEquals($expected, $result['message']);
         $this->assertLineLengths($result['message']);
+
+        $line = 'some text <b>with html</b>';
+        $trailing = str_repeat('X', Email::LINE_LENGTH_MUST - strlen($line));
+        $result = $this->Email->send($line . $trailing);
+        $expected = 'some text <b>with' . "\r\nhtml</b>" . $trailing . "\r\n\r\n";
+        $this->assertEquals($expected, $result['message']);
     }
 
     /**