Skip to content

Commit

Permalink
fixing regex of autoLinks to work with urls that have www
Browse files Browse the repository at this point in the history
  • Loading branch information
krolow committed Feb 14, 2012
1 parent ad09b91 commit 07adcfe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion lib/Cake/Test/Case/View/Helper/TextHelperTest.php
Expand Up @@ -336,6 +336,26 @@ public function testAutoLinkUrls() {
$expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link'; $expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false)); $result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

$text = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'Text with a url www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'Text with a url http://www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">http://www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);

$text = 'Text with a url http://www.www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.www.not-working-www.com">http://www.www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
} }


/** /**
Expand Down Expand Up @@ -424,7 +444,7 @@ public function testExcerpt() {
$expected = $text; $expected = $text;
$result = $this->Text->excerpt($text, $phrase, 13, '...'); $result = $this->Text->excerpt($text, $phrase, 13, '...');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

$text = 'aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa'; $text = 'aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa';
$phrase = 'bbbbbbbb'; $phrase = 'bbbbbbbb';
$result = $this->Text->excerpt($text, $phrase, 10); $result = $this->Text->excerpt($text, $phrase, 10);
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/View/Helper/TextHelper.php
Expand Up @@ -121,7 +121,7 @@ public function autoLinkUrls($text, $htmlOptions = array()) {
$text $text
); );
return preg_replace_callback( return preg_replace_callback(
'#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i', '#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
array(&$this, '_linkUrls'), array(&$this, '_linkUrls'),
$text $text
); );
Expand Down Expand Up @@ -353,7 +353,7 @@ public function excerpt($text, $phrase, $radius = 100, $ending = '...') {


$excerpt = mb_substr($text, $startPos, $endPos - $startPos); $excerpt = mb_substr($text, $startPos, $endPos - $startPos);
$excerpt = $prepend . $excerpt . $append; $excerpt = $prepend . $excerpt . $append;

return $excerpt; return $excerpt;
} }


Expand Down

0 comments on commit 07adcfe

Please sign in to comment.