Skip to content

Commit

Permalink
Fixing TextHelper::autoLinkEmails() not linking email addresses that …
Browse files Browse the repository at this point in the history
…contain '.

Test added.
Fixes #1457
  • Loading branch information
markstory committed Jan 17, 2011
1 parent ca299a0 commit b0d4951
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cake/libs/view/helpers/text.php
Expand Up @@ -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);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions cake/tests/cases/libs/view/helpers/text.test.php
Expand Up @@ -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';
Expand Down

0 comments on commit b0d4951

Please sign in to comment.