Skip to content
This repository
Browse code

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

…contain '.

Test added.
Fixes #1457
  • Loading branch information...
commit b0d495118482914161e48ec7d0932d0a366973fe 1 parent ca299a0
Mark Story authored January 17, 2011
6  cake/libs/view/helpers/text.php
@@ -142,9 +142,11 @@ function autoLinkEmails($text, $options = array()) {
142 142
 			$linkOptions .= "'$option' => $value, ";
143 143
 		}
144 144
 		$linkOptions .= ')';
  145
+		$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
145 146
 
146  
-		return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
147  
-						create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
  147
+		return preg_replace_callback(
  148
+			'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i',
  149
+			create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
148 150
 	}
149 151
 
150 152
 /**
5  cake/tests/cases/libs/view/helpers/text.test.php
@@ -298,6 +298,11 @@ function testAutoLinkEmails() {
298 298
 		$expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
299 299
 		$result = $this->Text->autoLinkEmails($text);
300 300
 		$this->assertPattern('#^' . $expected . '$#', $result);
  301
+		
  302
+		$text = "Text with o'hare._-bob@example.com address";
  303
+		$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
  304
+		$result = $this->Text->autoLinkEmails($text);
  305
+		$this->assertEqual($expected, $result);
301 306
 
302 307
 		$text = 'Text with email@example.com address';
303 308
 		$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';

0 notes on commit b0d4951

Please sign in to comment.
Something went wrong with that request. Please try again.