Skip to content

Commit

Permalink
Forward port #5544 to 3.0.
Browse files Browse the repository at this point in the history
Given that the merges between 2.x and 3.x have stopped, bugfixes need to
be manually merged forward.
  • Loading branch information
markstory committed Jan 3, 2015
1 parent fb2ec09 commit d408bfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/View/Helper/TextHelper.php
Expand Up @@ -117,7 +117,10 @@ public function autoLinkUrls($text, array $options = [])
$this->_placeholders = [];
$options += ['escape' => true];

$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[/?][^\s<]*)?)#ui';

$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+' .
'(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+' .
'(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i';
$text = preg_replace_callback(
$pattern,
[&$this, '_insertPlaceHolder'],
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/View/Helper/TextHelperTest.php
Expand Up @@ -174,6 +174,31 @@ public function testAutoLink()
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>(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 (<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>) 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 [<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>] 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 [<a href="http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3">http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3</a>] 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 ;<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>; 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 (<a href="http://www.cakephp.org/page/4/other(thing)">http://www.cakephp.org/page/4/other(thing)</a>) brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
}

/**
Expand Down

0 comments on commit d408bfd

Please sign in to comment.