From b1dfab87e44f4248ea9263627456cab23eb63b5c Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 11 Oct 2012 08:16:51 -0400 Subject: [PATCH] Fix autoLinkUrls so it re-capture query strings. Fixes #3296 --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 15 +++++++++++++++ lib/Cake/View/Helper/TextHelper.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 2c04eb15435..fe7ac135d99 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -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 www.cakephp.org:8080'; + $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 http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; $result = $this->Text->autoLinkUrls($text); @@ -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 http://example.com/test.php?foo=bar 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 www.example.com/test.php?foo=bar text'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEquals($expected, $result); + $text = 'Text with a partial www.cakephp.org URL'; $expected = 'Text with a partial www.cakephp.org URL'; $result = $this->Text->autoLinkUrls($text); diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index c7523b4254c..1601a5464f7 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -101,7 +101,7 @@ public function autoLinkUrls($text, $options = array()) { $this->_placeholders = array(); $options += array('escape' => true); - $pattern = '#(?)((?:https?|ftp|nntp)://[^\s<>()]+\.[a-z]+(?:\/[^\s]+)?)#i'; + $pattern = '#(?)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i'; $text = preg_replace_callback( $pattern, array(&$this, '_insertPlaceHolder'),