Bug #28248
closedt3lib_div::substUrlsInPlainText didn't recognize URLs at the end of a sentence correctly
100%
Description
e.g.
To unsubscribe use http://unsubscribe.com.
detects "http://unsubscribe.com." as URL.
I've shortened the substUrlsInPlainText function:
function substUrlsInPlainText($message,$urlmode='76',$index_script_url='') {
return preg_replace('/(http|https):\/\/.+(?=[\]\.\?]*([\! \'"()<>]+|$))/eiU','self::makeRedirectUrl("\\0",'.intval($urlmode).',"'.$index_script_url.'")',$message);
}
The regex:
(http|https):\/\/.+ -> Everything which starts with http:// or https://
(?=[\]\.\?]* -> and not end with "]", "." or "?" (these are also allowed in the url)
([\! \'"()<>]+|$)) -> and end with one of these is an url...
I've checked this with the following messages:
'http://only-url.com',
'https://only-secure-url.com',
'A http://url in the sentence.',
'URL in round brackets (http://www.example.com) in the sentence.',
'URL in square brackets [http://www.example.com/a/b.php?c[d]=e] in the sentence.',
'URL in square brackets at the end of the sentence [http://www.example.com/a/b.php?c[d]=e].',
'Square brackets in the http://www.url.com?tt_news[uid]=1',
'URL with http://dot.com.',
'URL in <a href="http://www.example.com/">a tag</a>',
'URL in HTML <b>http://www.example.com</b><br />',
'URL with http://username@example.com/',
'URL in quotation marks "http://example.com"',
'URL with umlauts http://müller.de',
'Secret in URL http://username:secret@example.com',
'Multiline
text with a http://url.com',
'http://www.shout.com!',
'And last but not least http://www.two.com/abc http://urls.com/abc?x=1&y=2',
Files