Skip to content
This repository
Browse code

Fix autoLinkUrls so it re-capture query strings.

Fixes #3296
  • Loading branch information...
commit b1dfab87e44f4248ea9263627456cab23eb63b5c 1 parent f06bdde
Mark Story authored October 11, 2012
15  lib/Cake/Test/Case/View/Helper/TextHelperTest.php
@@ -181,6 +181,11 @@ public function testAutoLinkUrls() {
181 181
 		$result = $this->Text->autoLinkUrls($text);
182 182
 		$this->assertEquals($expected, $result);
183 183
 
  184
+		$text = 'This is a test that includes www.cakephp.org:8080';
  185
+		$expected = 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>';
  186
+		$result = $this->Text->autoLinkUrls($text);
  187
+		$this->assertEquals($expected, $result);
  188
+
184 189
 		$text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
185 190
 		$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>';
186 191
 		$result = $this->Text->autoLinkUrls($text);
@@ -191,6 +196,16 @@ public function testAutoLinkUrls() {
191 196
 		$result = $this->Text->autoLinkUrls($text);
192 197
 		$this->assertEquals($expected, $result);
193 198
 
  199
+		$text = 'This is a test that includes http://example.com/test.php?foo=bar text';
  200
+		$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';
  201
+		$result = $this->Text->autoLinkUrls($text);
  202
+		$this->assertEquals($expected, $result);
  203
+
  204
+		$text = 'This is a test that includes www.example.com/test.php?foo=bar text';
  205
+		$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';
  206
+		$result = $this->Text->autoLinkUrls($text);
  207
+		$this->assertEquals($expected, $result);
  208
+
194 209
 		$text = 'Text with a partial www.cakephp.org URL';
195 210
 		$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
196 211
 		$result = $this->Text->autoLinkUrls($text);
2  lib/Cake/View/Helper/TextHelper.php
@@ -101,7 +101,7 @@ public function autoLinkUrls($text, $options = array()) {
101 101
 		$this->_placeholders = array();
102 102
 		$options += array('escape' => true);
103 103
 
104  
-		$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[^\s<>()]+\.[a-z]+(?:\/[^\s]+)?)#i';
  104
+		$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i';
105 105
 		$text = preg_replace_callback(
106 106
 			$pattern,
107 107
 			array(&$this, '_insertPlaceHolder'),

0 notes on commit b1dfab8

Please sign in to comment.
Something went wrong with that request. Please try again.