Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fixing regex of autoLinks to work with urls that have www #477

Merged
merged 1 commit into from

2 participants

@krolow

When you put to autoLink texts, with www in the middle of url, the autoLink was adding the a tag twice... e.g: http://www.not-working-www.com

So I have changed the regex and also add some test to fix that.

http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2574

@markstory
Owner

Thanks for the patch and test cases :D

@markstory markstory merged commit ba249ae into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 14, 2012
  1. @krolow
This page is out of date. Refresh to see the latest.
View
22 lib/Cake/Test/Case/View/Helper/TextHelperTest.php
@@ -336,6 +336,26 @@ public function testAutoLinkUrls() {
$expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$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);
}
/**
@@ -424,7 +444,7 @@ public function testExcerpt() {
$expected = $text;
$result = $this->Text->excerpt($text, $phrase, 13, '...');
$this->assertEquals($expected, $result);
-
+
$text = 'aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa';
$phrase = 'bbbbbbbb';
$result = $this->Text->excerpt($text, $phrase, 10);
View
4 lib/Cake/View/Helper/TextHelper.php
@@ -121,7 +121,7 @@ public function autoLinkUrls($text, $htmlOptions = array()) {
$text
);
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'),
$text
);
@@ -353,7 +353,7 @@ public function excerpt($text, $phrase, $radius = 100, $ending = '...') {
$excerpt = mb_substr($text, $startPos, $endPos - $startPos);
$excerpt = $prepend . $excerpt . $append;
-
+
return $excerpt;
}
Something went wrong with that request. Please try again.