in Helper.urls2links(), encode HTML entities, find and insert links, partially decoding only the href property of it

This commit is contained in:
El RIDO 2020-02-29 09:37:54 +01:00
parent d2e9e47b67
commit 5340f417e0
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
4 changed files with 25 additions and 13 deletions

View file

@ -297,10 +297,25 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/
me.urls2links = function(html)
{
return html.replace(
/(((https?|ftp):\/\/[\w?!=&.\/-;#@~%+*-]+(?![\w\s?!&.\/;#~%"=-]*>))|((magnet):[\w?=&.\/-;#@~%+*-]+))/ig,
'<a href="$1" rel="nofollow">$1</a>'
);
let reverseEntityMap = {};
for (let entity of ['&', '"', '/', '=']) {
reverseEntityMap[entityMap[entity]] = entity;
}
const entityRegex = new RegExp(Object.keys(reverseEntityMap).join('|'), 'g');
// encode HTML entities, find and insert links, partially decoding only the href property of it
return me.htmlEntities(html)
.replace(
/(((https?|ftp):&#x2F;&#x2F;[\w?!&.-;#@~%+*-]+(?![\w\s?!&.;#~%-]*>))|((magnet):[\w?&.-;#@~%+*-]+))/ig,
function(encodedUrl) {
let decodedUrl = encodedUrl.replace(
entityRegex, function(entity) {
return reverseEntityMap[entity];
}
);
return '<a href="' + decodedUrl + '" rel="nofollow">' + encodedUrl + '</a>';
}
)
};
/**