From 74d8e9ea409b052f685029e143c73fd9395686eb Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 16 Jun 2014 21:42:54 -0400 Subject: [PATCH 1/2] Convert test to use a dataprovider instead of multiple calls. Dataproviders are generally a bit easier to work with in the future. --- .../Test/Case/View/Helper/TextHelperTest.php | 91 +++++++++++-------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 9586b5864..ba1accc9a 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -363,54 +363,71 @@ class TextHelperTest extends CakeTestCase { } /** - * testAutoLinkEmails method + * Data provider for autoLinkEmail. * * @return void */ - public function testAutoLinkEmails() { - $text = 'This is a test text'; - $expected = 'This is a test text'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); + public function autoLinkEmailProvider() { + return array( + array( + 'This is a test text', + 'This is a test text', + ), - $text = 'email@example.com address'; - $expected = 'email@example.com address'; - $result = $this->Text->autoLinkEmails($text); - $this->assertEquals($expected, $result); + array( + 'email@example.com address', + 'email@example.com address', + ), - $text = 'email@example.com address'; - $expected = 'email@example.com address'; - $result = $this->Text->autoLinkEmails($text); - $this->assertEquals($expected, $result); + array( + 'email@example.com address', + 'email@example.com address', + ), - $text = '(email@example.com) address'; - $expected = '(email@example.com) address'; - $result = $this->Text->autoLinkEmails($text); - $this->assertEquals($expected, $result); + array( + '(email@example.com) address', + '(email@example.com) address', + ), - $text = 'Text with email@example.com address'; - $expected = 'Text with email@example.com address'; - $result = $this->Text->autoLinkEmails($text); - $this->assertEquals($expected, $result); + array( + 'Text with email@example.com address', + 'Text with email@example.com address', + ), - $text = "Text with o'hare._-bob@example.com address"; - $expected = 'Text with o'hare._-bob@example.com address'; - $result = $this->Text->autoLinkEmails($text); - $this->assertEquals($expected, $result); + array( + "Text with o'hare._-bob@example.com address", + 'Text with o'hare._-bob@example.com address', + ), - $text = 'Text with email@example.com address'; - $expected = 'Text with email@example.com address'; - $result = $this->Text->autoLinkEmails($text, array('class' => 'link')); - $this->assertEquals($expected, $result); + array( + 'Text with düsentrieb@küchenschöhn-not-working.de address', + 'Text with düsentrieb@küchenschöhn-not-working.de address', + ), - $text = 'Text with düsentrieb@küchenschöhn-not-working.de address'; - $expected = 'Text with düsentrieb@küchenschöhn-not-working.de address'; - $result = $this->Text->autoLinkEmails($text); - $this->assertEquals($expected, $result); + array( + 'Text with me@subdomain.küchenschöhn.de address', + 'Text with me@subdomain.küchenschöhn.de address', + ), - $text = 'Text with me@subdomain.küchenschöhn.de address'; - $expected = 'Text with me@subdomain.küchenschöhn.de address'; - $result = $this->Text->autoLinkEmails($text); + array( + 'Text with email@example.com address', + 'Text with email@example.com address', + array('class' => 'link'), + ), + + ); + } + +/** + * testAutoLinkEmails method + * + * @param string $text The text to link + * @param string $expected The expected results. + * @dataProvider autoLinkEmailProvider + * @return void + */ + public function testAutoLinkEmails($text, $expected, $attrs = array()) { + $result = $this->Text->autoLinkEmails($text, $attrs); $this->assertEquals($expected, $result); } From 9136f6387486c80d72e8b8197e784f80c1d02fa0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 16 Jun 2014 21:48:30 -0400 Subject: [PATCH 2/2] Fix autoLinkEmail() not working when emails are adjacent to HTML. When an email address is adjacent to HTML it should be autolinked correctly. Refs #3656 --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 11 +++++++++++ lib/Cake/View/Helper/TextHelper.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index ba1accc9a..0c93e3085 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -415,6 +415,17 @@ class TextHelperTest extends CakeTestCase { array('class' => 'link'), ), + array( + '

mark@example.com

', + '

mark@example.com

', + array('escape' => false) + ), + + array( + 'Some mark@example.com Text', + 'Some mark@example.com Text', + array('escape' => false) + ), ); } diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index f5492535d..d90b34af1 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -190,7 +190,7 @@ class TextHelper extends AppHelper { $atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]'; $text = preg_replace_callback( - '/(?<=\s|^|\()(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui', + '/(?<=\s|^|\(|\>|\;)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui', array(&$this, '_insertPlaceholder'), $text );