Skip to content

Commit

Permalink
Fix doubly linking URLs starting with //
Browse files Browse the repository at this point in the history
Fixes #5889
  • Loading branch information
markstory committed Feb 14, 2015
1 parent 3dfa22b commit b3c9c16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/Cake/Test/Case/View/Helper/TextHelperTest.php
Expand Up @@ -127,6 +127,10 @@ public function testAutoLink() {
$expected = 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL and <a href="mailto:test@cakephp\.org">test@cakephp\.org</a> email address';
$this->assertRegExp('#^' . $expected . '$#', $result);

$text = 'Text with a partial <a href="//www.cakephp.org">link</a> link';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($text, $result);

$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/TextHelper.php
Expand Up @@ -114,7 +114,7 @@ public function autoLinkUrls($text, $options = array()) {
$text
);
$text = preg_replace_callback(
'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://|//)www.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
array(&$this, '_insertPlaceHolder'),
$text
);
Expand Down

0 comments on commit b3c9c16

Please sign in to comment.