Browse Source

Fix incorrect autolinking when urls end at HTML tags.

Fixes #3879
mark_story 12 years ago
parent
commit
111bfa43d4

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

@@ -171,6 +171,17 @@ class TextHelperTest extends CakeTestCase {
 		$expected = 'This is a <b>test</b> text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
 		$result = $this->Text->autoLink($text, array('escape' => false));
 		$this->assertEquals($expected, $result);
+
+		$text = 'test <ul>
+		<li>lorem: http://example.org?some</li>
+		<li>ipsum: http://othersite.com/abc</li>
+		</ul> test';
+		$expected = 'test <ul>
+		<li>lorem: <a href="http://example.org?some">http://example.org?some</a></li>
+		<li>ipsum: <a href="http://othersite.com/abc">http://othersite.com/abc</a></li>
+		</ul> test';
+		$result = $this->Text->autoLink($text, array('escape' => false));
+		$this->assertEquals($expected, $result);
 	}
 
 /**

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

@@ -105,7 +105,7 @@ class TextHelper extends AppHelper {
 		$this->_placeholders = array();
 		$options += array('escape' => true);
 
-		$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:[/?][^\s]*)?)#i';
+		$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:[/?][^\s<]*)?)#i';
 		$text = preg_replace_callback(
 			$pattern,
 			array(&$this, '_insertPlaceHolder'),