Skip to content
This repository
Browse code

Merge pull request #477 from krolow/ticket-2574

fixing regex of autoLinks to work with urls that have www
  • Loading branch information...
commit ba249aeff69575e25c09ea86cc2701d19c74f67c 2 parents ad09b91 + 07adcfe
Mark Story authored February 14, 2012
22  lib/Cake/Test/Case/View/Helper/TextHelperTest.php
@@ -336,6 +336,26 @@ public function testAutoLinkUrls() {
336 336
 		$expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
337 337
 		$result = $this->Text->autoLinkUrls($text, array('escape' => false));
338 338
 		$this->assertEquals($expected, $result);
  339
+
  340
+		$text = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
  341
+		$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
  342
+		$result = $this->Text->autoLinkUrls($text);
  343
+		$this->assertEquals($expected, $result);
  344
+
  345
+		$text = 'Text with a url www.not-working-www.com and more';
  346
+		$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
  347
+		$result = $this->Text->autoLinkUrls($text);
  348
+		$this->assertEquals($expected, $result);
  349
+
  350
+		$text = 'Text with a url http://www.not-working-www.com and more';
  351
+		$expected = 'Text with a url <a href="http://www.not-working-www.com">http://www.not-working-www.com</a> and more';
  352
+		$result = $this->Text->autoLinkUrls($text);
  353
+		$this->assertEquals($expected, $result);
  354
+
  355
+		$text = 'Text with a url http://www.www.not-working-www.com and more';
  356
+		$expected = 'Text with a url <a href="http://www.www.not-working-www.com">http://www.www.not-working-www.com</a> and more';
  357
+		$result = $this->Text->autoLinkUrls($text);
  358
+		$this->assertEquals($expected, $result);
339 359
 	}
340 360
 
341 361
 /**
@@ -424,7 +444,7 @@ public function testExcerpt() {
424 444
 		$expected = $text;
425 445
 		$result = $this->Text->excerpt($text, $phrase, 13, '...');
426 446
 		$this->assertEquals($expected, $result);
427  
-		
  447
+
428 448
 		$text = 'aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa';
429 449
 		$phrase = 'bbbbbbbb';
430 450
 		$result = $this->Text->excerpt($text, $phrase, 10);
4  lib/Cake/View/Helper/TextHelper.php
@@ -121,7 +121,7 @@ public function autoLinkUrls($text, $htmlOptions = array()) {
121 121
 			$text
122 122
 		);
123 123
 		return preg_replace_callback(
124  
-			'#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
  124
+			'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
125 125
 			array(&$this, '_linkUrls'),
126 126
 			$text
127 127
 		);
@@ -353,7 +353,7 @@ public function excerpt($text, $phrase, $radius = 100, $ending = '...') {
353 353
 
354 354
 		$excerpt = mb_substr($text, $startPos, $endPos - $startPos);
355 355
 		$excerpt = $prepend . $excerpt . $append;
356  
-		
  356
+
357 357
 		return $excerpt;
358 358
 	}
359 359
 

0 notes on commit ba249ae

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