Skip to content

Commit

Permalink
Fix autoLinkUrls so it re-capture query strings.
Browse files Browse the repository at this point in the history
Fixes #3296
  • Loading branch information
markstory committed Oct 11, 2012
1 parent f06bdde commit b1dfab8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/Cake/Test/Case/View/Helper/TextHelperTest.php
Expand Up @@ -181,6 +181,11 @@ public function testAutoLinkUrls() {
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'This is a test that includes www.cakephp.org:8080';
$expected = 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
$expected = 'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
$result = $this->Text->autoLinkUrls($text);
Expand All @@ -191,6 +196,16 @@ public function testAutoLinkUrls() {
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'This is a test that includes http://example.com/test.php?foo=bar text';
$expected = 'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'This is a test that includes www.example.com/test.php?foo=bar text';
$expected = 'This is a test that includes <a href="http://www.example.com/test.php?foo=bar">www.example.com/test.php?foo=bar</a> text';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
$result = $this->Text->autoLinkUrls($text);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/TextHelper.php
Expand Up @@ -101,7 +101,7 @@ public function autoLinkUrls($text, $options = array()) {
$this->_placeholders = array();
$options += array('escape' => true);

$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[^\s<>()]+\.[a-z]+(?:\/[^\s]+)?)#i';
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i';
$text = preg_replace_callback(
$pattern,
array(&$this, '_insertPlaceHolder'),
Expand Down

0 comments on commit b1dfab8

Please sign in to comment.