diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index c4e36aaa7..41ef4b296 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -146,6 +146,31 @@ class TextHelperTest extends CakeTestCase { $expected = 'This is a test text with URL http://www.cakephp.org(and some more text)'; $result = $this->Text->autoLink($text); $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets'; + $expected = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL [http://www.cakephp.org/page/4] in square brackets'; + $expected = 'This is a test text with URL [http://www.cakephp.org/page/4] in square brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets'; + $expected = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon'; + $expected = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); + + $text = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets'; + $expected = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets'; + $result = $this->Text->autoLink($text); + $this->assertEquals($expected, $result); } /** diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index 6e9684765..92d30ace6 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -107,7 +107,7 @@ class TextHelper extends AppHelper { $this->_placeholders = array(); $options += array('escape' => true); - $pattern = '#(?)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[/?][^\s<]*)?)#ui'; + $pattern = '#(?)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i'; $text = preg_replace_callback( $pattern, array(&$this, '_insertPlaceHolder'),