From a9ca1bdc58727d096d764f0618de3d9eb3e2cc5e Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 29 Nov 2013 22:57:43 -0500 Subject: [PATCH] Add tests and fix other cases where autoLinkEmail would fail. Refs #2403 --- .../Test/Case/View/Helper/TextHelperTest.php | 29 ++++++++++++++----- lib/Cake/View/Helper/TextHelper.php | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 6b5d86621..73c021c74 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -363,10 +363,25 @@ class TextHelperTest extends CakeTestCase { $result = $this->Text->autoLinkUrls($text); $this->assertEquals($expected, $result); - $text = 'Text with email@example.com address'; - $expected = 'Text with email@example.com address'; + $text = 'email@example.com address'; + $expected = 'email@example.com address'; $result = $this->Text->autoLinkEmails($text); - $this->assertRegExp('#^' . $expected . '$#', $result); + $this->assertEquals($expected, $result); + + $text = 'email@example.com address'; + $expected = 'email@example.com address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertEquals($expected, $result); + + $text = '(email@example.com) address'; + $expected = '(email@example.com) address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertEquals($expected, $result); + + $text = 'Text with email@example.com address'; + $expected = 'Text with email@example.com address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertEquals($expected, $result); $text = "Text with o'hare._-bob@example.com address"; $expected = 'Text with o'hare._-bob@example.com address'; @@ -374,19 +389,19 @@ class TextHelperTest extends CakeTestCase { $this->assertEquals($expected, $result); $text = 'Text with email@example.com address'; - $expected = 'Text with email@example.com address'; + $expected = 'Text with email@example.com address'; $result = $this->Text->autoLinkEmails($text, array('class' => 'link')); - $this->assertRegExp('#^' . $expected . '$#', $result); + $this->assertEquals($expected, $result); $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->assertRegExp('#^' . $expected . '$#', $result); + $this->assertEquals($expected, $result); $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); - $this->assertRegExp('#^' . $expected . '$#', $result); + $this->assertEquals($expected, $result); } /** diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index c418a54de..a3f07856c 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -187,7 +187,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 );