Improve url finding more. Properly end urls when a space is caught.
This commit is contained in:
parent
0615fda25e
commit
579a41b56f
13
lib/util.php
13
lib/util.php
@ -412,13 +412,15 @@ function common_render_text($text)
|
|||||||
function common_replace_urls_callback($text, $callback, $notice_id = null) {
|
function common_replace_urls_callback($text, $callback, $notice_id = null) {
|
||||||
// Start off with a regex
|
// Start off with a regex
|
||||||
$regex = '#'.
|
$regex = '#'.
|
||||||
'(?:^|[\s\(\)\[\]\{\}]+)('.
|
'(?:^|[\s\(\)\[\]\{\}]+)'.
|
||||||
|
'('.
|
||||||
|
'(?:'.
|
||||||
'(?:'. //Known protocols
|
'(?:'. //Known protocols
|
||||||
'(?:'.
|
'(?:'.
|
||||||
'(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'.
|
'(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'.
|
||||||
'|'.
|
'|'.
|
||||||
'(?:mailto|aim|tel|xmpp):'.
|
'(?:mailto|aim|tel|xmpp):'.
|
||||||
')[^\s\(\)\[\]\{\}]+'.
|
')[^\s\/]+'.
|
||||||
')'.
|
')'.
|
||||||
'|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'. //IPv4
|
'|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'. //IPv4
|
||||||
'|(?:'. //IPv6
|
'|(?:'. //IPv6
|
||||||
@ -442,7 +444,12 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) {
|
|||||||
')|(?:'. //DNS
|
')|(?:'. //DNS
|
||||||
'\S+\.(?:museum|travel|onion|local|[a-z]{2,4})'.
|
'\S+\.(?:museum|travel|onion|local|[a-z]{2,4})'.
|
||||||
')'.
|
')'.
|
||||||
'([^\s\(\)\[\]\{\}]*)'.
|
')'.
|
||||||
|
'(?:'.
|
||||||
|
'$|(?:'.
|
||||||
|
'/[^\s\(\)\[\]\{\}]*'.
|
||||||
|
')'.
|
||||||
|
')'.
|
||||||
')'.
|
')'.
|
||||||
'#ix';
|
'#ix';
|
||||||
return preg_replace_callback($regex, curry(callback_helper,$callback,$notice_id) ,$text);
|
return preg_replace_callback($regex, curry(callback_helper,$callback,$notice_id) ,$text);
|
||||||
|
Loading…
Reference in New Issue
Block a user