Browse Source

Fix autoLinkUrls() not autolinking URL's without a /.

Refs #GH-1259
mark_story 13 years ago
parent
commit
41d124d4de

+ 12 - 0
lib/Cake/Test/Case/View/Helper/TextHelperTest.php

@@ -297,6 +297,18 @@ class TextHelperTest extends CakeTestCase {
 	}
 
 /**
+ * Test autoLinkUrls with query strings.
+ *
+ * @return void
+ */
+	public function testAutoLinkUrlsQueryString() {
+		$text = 'Text with a partial http://www.cakephp.org?product_id=123&foo=bar link';
+		$expected = 'Text with a partial <a href="http://www.cakephp.org?product_id=123&amp;foo=bar">http://www.cakephp.org?product_id=123&amp;foo=bar</a> link';
+		$result = $this->Text->autoLinkUrls($text);
+		$this->assertEquals($expected, $result);
+	}
+
+/**
  * testAutoLinkEmails method
  *
  * @return void

+ 1 - 1
lib/Cake/View/Helper/TextHelper.php

@@ -105,7 +105,7 @@ class TextHelper extends AppHelper {
 		$this->_placeholders = array();
 		$options += array('escape' => true);
 
-		$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i';
+		$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:[/?][^\s]*)?)#i';
 		$text = preg_replace_callback(
 			$pattern,
 			array(&$this, '_insertPlaceHolder'),