mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-07-31 18:48:35 -04:00
in Helper.urls2links(), encode HTML entities, find and insert links, partially decoding only the href property of it
This commit is contained in:
parent
d2e9e47b67
commit
5340f417e0
4 changed files with 25 additions and 13 deletions
|
@ -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)://[\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>';
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue