From b80a8947d7f2cc0396a256ecc711b10961b4f8ae Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 23 Feb 2015 21:37:49 -0500 Subject: [PATCH] Check line length to account for fence post. When we have exactly 998 bytes CakeEmail should not emit an error. Refs #5948 --- lib/Cake/Network/Email/CakeEmail.php | 2 +- .../Test/Case/Network/Email/CakeEmailTest.php | 19 +++++++++++++++++++ .../test_app/View/Emails/html/long_line.ctp | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/Cake/Test/test_app/View/Emails/html/long_line.ctp diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 4cae10499..b9d557cf3 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1421,7 +1421,7 @@ class CakeEmail { $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 = ''; diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 1dc125fea..c6bed1d73 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -2435,6 +2435,25 @@ HTML; $this->assertEquals($expected, $result['message']); } +/** + * Test that really long lines don't cause errors. + * + * @return void + */ + public function testReallyLongLine() { + $this->CakeEmail->reset(); + $this->CakeEmail->config(array('empty')); + $this->CakeEmail->transport('Debug'); + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to('cake@cakephp.org'); + $this->CakeEmail->subject('Wordwrap Test'); + $this->CakeEmail->emailFormat('html'); + $this->CakeEmail->template('long_line', null); + $result = $this->CakeEmail->send(); + $this->assertContains('', $result['message'], 'First bits are included'); + $this->assertContains('x', $result['message'], 'Last byte are included'); + } + /** * CakeEmailTest::assertLineLengths() * diff --git a/lib/Cake/Test/test_app/View/Emails/html/long_line.ctp b/lib/Cake/Test/test_app/View/Emails/html/long_line.ctp new file mode 100644 index 000000000..4bf8bbdab --- /dev/null +++ b/lib/Cake/Test/test_app/View/Emails/html/long_line.ctp @@ -0,0 +1,14 @@ +34567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' . +'1234567890123456789012345678901234567890123456x';