From b0d495118482914161e48ec7d0932d0a366973fe Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 17 Jan 2011 11:11:30 -0500 Subject: [PATCH] Fixing TextHelper::autoLinkEmails() not linking email addresses that contain '. Test added. Fixes #1457 --- cake/libs/view/helpers/text.php | 6 ++++-- cake/tests/cases/libs/view/helpers/text.test.php | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 04e80a812..7d25ea349 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -142,9 +142,11 @@ class TextHelper extends AppHelper { $linkOptions .= "'$option' => $value, "; } $linkOptions .= ')'; + $atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]'; - return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#', - create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text); + return preg_replace_callback( + '/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i', + create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text); } /** diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index f4c18d628..295d9ce39 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -298,6 +298,11 @@ class TextHelperTest extends CakeTestCase { $expected = 'Text with email@example.com address'; $result = $this->Text->autoLinkEmails($text); $this->assertPattern('#^' . $expected . '$#', $result); + + $text = "Text with o'hare._-bob@example.com address"; + $expected = 'Text with o'hare._-bob@example.com address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertEqual($expected, $result); $text = 'Text with email@example.com address'; $expected = 'Text with email@example.com address';