diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 0e877e892..4e8fa232e 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -117,17 +117,10 @@ class TextHelper extends AppHelper { * @access public * @link http://book.cakephp.org/view/1469/Text#autoLinkUrls-1619 */ - function autoLinkUrls($text, $options = array()) { - $linkOptions = 'array('; - foreach ($options as $option => $value) { - $value = var_export($value, true); - $linkOptions .= "'$option' => $value, "; - } - $linkOptions .= ')'; - - $text = preg_replace_callback('#(?)((?:http|https|ftp|nntp)://[^ <]+)#i', create_function('$matches', - '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $linkOptions . ');'), $text); - + function autoLinkUrls($text, $htmlOptions = array()) { + $options = var_export($htmlOptions, true); + $text = preg_replace_callback('#(?)((?:https?|ftp|nntp)://[^\s<>()]+)#i', create_function('$matches', + '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text); return preg_replace_callback('#(?)(?tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $linkOptions . ');'), $text); } diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 042cce533..a2a6531b1 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -207,6 +207,36 @@ class TextHelperTest extends CakeTestCase { $result = $this->Text->autoLink($text); $expected = 'Text with a partial www.cakephp.org URL and test@cakephp\.org email address'; $this->assertPattern('#^' . $expected . '$#', $result); + + $text = 'This is a test text with URL http://www.cakephp.org'; + $expected = 'This is a test text with URL http://www.cakephp.org'; + $result = $this->Text->autoLink($text); + $this->assertEqual($result, $expected); + + $text = 'This is a test text with URL http://www.cakephp.org and some more text'; + $expected = 'This is a test text with URL http://www.cakephp.org and some more text'; + $result = $this->Text->autoLink($text); + $this->assertEqual($result, $expected); + + $text = "This is a test text with URL http://www.cakephp.org\tand some more text"; + $expected = "This is a test text with URL http://www.cakephp.org\tand some more text"; + $result = $this->Text->autoLink($text); + $this->assertEqual($result, $expected); + + $text = 'This is a test text with URL http://www.cakephp.org(and some more text)'; + $expected = 'This is a test text with URL http://www.cakephp.org(and some more text)'; + $result = $this->Text->autoLink($text); + $this->assertEqual($result, $expected); + + $text = 'This is a test text with URL http://www.cakephp.org'; + $expected = 'This is a test text with URL http://www.cakephp.org'; + $result = $this->Text->autoLink($text, array('class'=>'link')); + $this->assertEqual($result, $expected); + + $text = 'This is a test text with URL http://www.cakephp.org'; + $expected = 'This is a test text with URL http://www.cakephp.org'; + $result = $this->Text->autoLink($text, array('class'=>'link', 'id'=>'MyLink')); + $this->assertEqual($result, $expected); } /**