expanded unit tests to cover mega links, reverted regex to old one, but fixed to cover mega links, just to prove it works

This commit is contained in:
El RIDO 2018-08-11 07:33:33 +02:00
parent c468b74b9b
commit 10201dc463
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
6 changed files with 12 additions and 7 deletions

View file

@ -146,9 +146,8 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
*/
me.urls2links = function(html)
{
// URL part of RegEx: https://regex101.com/r/h4ACei/5
return html.replace(
/(((https?|ftp):\/\/(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+(:([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?@)?((([a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*[a-z][a-z0-9-]*[a-z0-9]?|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5]))(:\d+)?)(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?)?)?(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?|((magnet):[\w?=&.\/-;#@~%+*-]+)))/ig,
/(((https?|ftp):\/\/[\w?!=&.\/-;#@~%+*-]+(?![\w\s?!&.\/;#~%"=-]*>))|((magnet):[\w?=&.\/-;#@~%+*-]+))/ig,
'<a href="$1" rel="nofollow">$1</a>'
);
};