Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing TextHelper::autoLinkEmails() not linking email addresses that …

…contain '.

Test added.
Fixes #1457
  • Loading branch information...
commit b0d495118482914161e48ec7d0932d0a366973fe 1 parent ca299a0
Mark Story markstory authored
6 cake/libs/view/helpers/text.php
View
@@ -142,9 +142,11 @@ function autoLinkEmails($text, $options = array()) {
$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);
}
/**
5 cake/tests/cases/libs/view/helpers/text.test.php
View
@@ -298,6 +298,11 @@ function testAutoLinkEmails() {
$expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertPattern('#^' . $expected . '$#', $result);
+
+ $text = "Text with o'hare._-bob@example.com address";
+ $expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
+ $result = $this->Text->autoLinkEmails($text);
+ $this->assertEqual($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
Please sign in to comment.
Something went wrong with that request. Please try again.