Permalink
Browse files

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

…contain '.

Test added.
Fixes #1457
  • Loading branch information...
markstory committed Jan 17, 2011
1 parent ced8dcd commit fffa2865ec76bbadff7bd0675a328923fa3df36d
Showing with 7 additions and 1 deletion.
  1. +2 −1 cake/libs/view/helpers/text.php
  2. +5 −0 cake/tests/cases/libs/view/helpers/text.test.php
@@ -125,8 +125,9 @@ function autoLinkEmails($text, $htmlOptions = array()) {
$options .= "'$option' => '$value', ";
}
$options .= ')';
+ $atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
- return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
+ 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],' . $options . ');'), $text);
}
/**
@@ -288,6 +288,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';

0 comments on commit fffa286

Please sign in to comment.