forked from GNUsocial/gnu-social
Improved the URL tests, and improve the matcher so more tests are passed. The remaining failing tests I believe are incorrect.
This commit is contained in:
24
lib/util.php
24
lib/util.php
@@ -412,30 +412,34 @@ function common_render_text($text)
|
||||
function common_replace_urls_callback($text, $callback, $notice_id = null) {
|
||||
// Start off with a regex
|
||||
$regex = '#'.
|
||||
'(?:^|[\s\(\)\[\]\{\}]+)'.
|
||||
'('.
|
||||
'(?:^|[\s\(\)\[\]\{\}\\\'\\\";]+)(?![\@\!\#])'.
|
||||
'('.
|
||||
'(?:'.
|
||||
'(?:'. //Known protocols
|
||||
'(?:'.
|
||||
'(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'.
|
||||
'|'.
|
||||
'(?:mailto|aim|tel|xmpp):'.
|
||||
')[^\s\/]+'.
|
||||
')'.
|
||||
'(?:[\pN\pL\-\_\+]+(?:\:[\pN\pL\-\_\+]+)?\@)?'. //user:pass@
|
||||
'[\pN\pL\-\_\:\.]+(?<![\.\:])'. //dns
|
||||
')'.
|
||||
'|(?:(?: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
|
||||
'(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}(?:(?:[0-9A-Fa-f]{1,4})|:))|(?:(?:[0-9A-Fa-f]{1,4}:){6}(?::|(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})|(?::[0-9A-Fa-f]{1,4})))|(?:(?:[0-9A-Fa-f]{1,4}:){5}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?:[0-9A-Fa-f]{1,4}:){4}(?::[0-9A-Fa-f]{1,4}){0,1}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?:[0-9A-Fa-f]{1,4}:){3}(?::[0-9A-Fa-f]{1,4}){0,2}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?:[0-9A-Fa-f]{1,4}:){2}(?::[0-9A-Fa-f]{1,4}){0,3}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?:[0-9A-Fa-f]{1,4}:)(?::[0-9A-Fa-f]{1,4}){0,4}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?::(?::[0-9A-Fa-f]{1,4}){0,5}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))'.
|
||||
')|(?:'. //DNS
|
||||
'\S+\.(?:museum|travel|onion|local|[a-z]{2,4})'.
|
||||
')'.
|
||||
'(?:[\pN\pL\-\_\+]+(?:\:[\pN\pL\-\_\+]+)?\@)?'. //user:pass@
|
||||
'[\pN\pL\-\_]+(?:\.[\pN\pL\-\_]+)*\.(?:museum|travel|onion|local|[a-z]{2,4})'.
|
||||
')(?![\pN\pL\-\_])'.
|
||||
')'.
|
||||
'(?:'.
|
||||
'$|(?:'.
|
||||
'/[^\s\(\)\[\]\{\}]*'.
|
||||
')'.
|
||||
')'.
|
||||
'(?:\:\d+)?'. //:port
|
||||
'(?:/[\pN\pL$\!\(\)\.\-\_\+\/\=\&\;]*)?'. // /path
|
||||
'(?:\?[\pN\pL\$\!\(\)\.\-\_\+\/\=\&\;\/]*)?'. // ?query string
|
||||
'(?:\#[\pN\pL$\!\(\)\.\-\_\+\/\=\&\;\/\?\#]*)?'. // #fragment
|
||||
')(?<![\?\.\,\#\)])'.
|
||||
')'.
|
||||
'#ix';
|
||||
'#ixu';
|
||||
return preg_replace_callback($regex, curry(callback_helper,$callback,$notice_id) ,$text);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user