change regex to support links with only protocol #198
This commit is contained in:
parent
339b9f16f3
commit
8885310232
|
@ -16,7 +16,7 @@ trait Formatter_Text {
|
|||
* @return string Texts with url's transformed in html tag <a>
|
||||
*/
|
||||
public function make_clickable_links($text) {
|
||||
$url = '~((http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)?www\.[^"<\s]+)(?![^<>]*>|[^"]*?<\/a)~i';
|
||||
$url = '~((www\.|http:\/\/www\.|http:\/\/|https:\/\/www\.|https:\/\/|ftp:\/\/www\.|ftp:\/\/|ftps:\/\/www\.|ftps:\/\/)[^"<\s]+)(?![^<>]*>|[^"]*?<\/a)~i';
|
||||
$text = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $text);
|
||||
return $text;
|
||||
}
|
||||
|
|
|
@ -158,11 +158,16 @@ class TestUtilities extends TAINACAN_UnitTestCase {
|
|||
' <a href="www.simple.com.br" target="_blank" title="www.simple.com.br">www.simple.com.br</a> ' .
|
||||
' <a href="www.simple.com" target="_blank" title="www.simple.com">www.simple.com</a> ' .
|
||||
' <a href="www.simple.org" target="_blank" title="www.simple.org">www.simple.org</a> ' .
|
||||
' Pellentesque id //ww.lair.com.br of a http://wwwliar.com.br euismod mauris. //pegadinha.com.br ';
|
||||
' Pellentesque id //ww.lair.com.br of a <a href="http://wwwliar.com.br" target="_blank" title="http://wwwliar.com.br">http://wwwliar.com.br</a> euismod mauris. //pegadinha.com.br ';
|
||||
|
||||
$text_multiple_links_response = $text->make_clickable_links($text_multiple_links);
|
||||
$this->assertEquals($text_multiple_links_expected, $text_multiple_links_response);
|
||||
|
||||
$text_multiple_links = 'Lorem https://tainacan.org hahahahahahhttps://tainacan.org hahaha ';
|
||||
$text_multiple_links_expected = 'Lorem <a href="https://tainacan.org" target="_blank" title="https://tainacan.org">https://tainacan.org</a> hahahahahah<a href="https://tainacan.org" target="_blank" title="https://tainacan.org">https://tainacan.org</a> hahaha ';
|
||||
$text_multiple_links_response = $text->make_clickable_links($text_multiple_links);
|
||||
$this->assertEquals($text_multiple_links_expected, $text_multiple_links_response);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue