Browse Source

Fix autoLinkEmail() not working when emails are adjacent to HTML.

When an email address is adjacent to HTML it should be autolinked
correctly.

Refs #3656
mark_story 11 years ago
parent
commit
9136f63874

+ 11 - 0
lib/Cake/Test/Case/View/Helper/TextHelperTest.php

@@ -415,6 +415,17 @@ class TextHelperTest extends CakeTestCase {
 				array('class' => 'link'),
 			),
 
+			array(
+				'<p>mark@example.com</p>',
+				'<p><a href="mailto:mark@example.com">mark@example.com</a></p>',
+				array('escape' => false)
+			),
+
+			array(
+				'Some&nbsp;mark@example.com&nbsp;Text',
+				'Some&nbsp;<a href="mailto:mark@example.com">mark@example.com</a>&nbsp;Text',
+				array('escape' => false)
+			),
 		);
 	}
 

+ 1 - 1
lib/Cake/View/Helper/TextHelper.php

@@ -190,7 +190,7 @@ class TextHelper extends AppHelper {
 
 		$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
 		$text = preg_replace_callback(
-			'/(?<=\s|^|\()(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
+			'/(?<=\s|^|\(|\>|\;)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
 			array(&$this, '_insertPlaceholder'),
 			$text
 		);