From 8a6dcf910a17c9458e458d26f266cea82b9b45f7 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Fri, 6 Mar 2020 20:57:15 +0100 Subject: [PATCH] Revert "in Helper.urls2links(), encode HTML entities, find and insert links, partially decoding only the href property of it" This reverts commit 5340f417e07fdfdab2f91f5171f4f992bc763a73. --- js/privatebin.js | 23 ++++------------------- js/test/Helper.js | 11 +++++++---- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 9e2b0ee2..d2b85448 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -297,25 +297,10 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ me.urls2links = function(html) { - 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 '' + encodedUrl + ''; - } - ) + return html.replace( + /(((https?|ftp):\/\/[\w?!=&.\/-;#@~%+*-]+(?![\w\s?!&.\/;#~%"=-]*>))|((magnet):[\w?=&.\/-;#@~%+*-]+))/ig, + '$1' + ); }; /** diff --git a/js/test/Helper.js b/js/test/Helper.js index a884eee2..dd38e3c4 100644 --- a/js/test/Helper.js +++ b/js/test/Helper.js @@ -81,7 +81,7 @@ describe('Helper', function () { 'ignores non-URL content', 'string', function (content) { - return $.PrivateBin.Helper.htmlEntities(content) === $.PrivateBin.Helper.urls2links(content); + return content === $.PrivateBin.Helper.urls2links(content); } ); jsc.property( @@ -95,7 +95,8 @@ describe('Helper', function () { function (prefix, schema, address, query, fragment, postfix) { query = query.join(''); fragment = fragment.join(''); - postfix = ' ' + postfix; + prefix = $.PrivateBin.Helper.htmlEntities(prefix); + postfix = ' ' + $.PrivateBin.Helper.htmlEntities(postfix); let url = schema + '://' + address.join('') + '/?' + query + '#' + fragment; // special cases: When the query string and fragment imply the beginning of an HTML entity, eg. � or &#x @@ -108,7 +109,7 @@ describe('Helper', function () { postfix = ''; } - return $.PrivateBin.Helper.htmlEntities(prefix) + '' + $.PrivateBin.Helper.htmlEntities(url) + '' + $.PrivateBin.Helper.htmlEntities(postfix) === $.PrivateBin.Helper.urls2links(prefix + url + postfix); + return prefix + '' + url + '' + postfix === $.PrivateBin.Helper.urls2links(prefix + url + postfix); } ); jsc.property( @@ -117,8 +118,10 @@ describe('Helper', function () { jsc.array(common.jscQueryString()), 'string', function (prefix, query, postfix) { + prefix = $.PrivateBin.Helper.htmlEntities(prefix); + postfix = $.PrivateBin.Helper.htmlEntities(postfix); let url = 'magnet:?' + query.join('').replace(/^&+|&+$/gm,''); - return $.PrivateBin.Helper.htmlEntities(prefix) + '' + $.PrivateBin.Helper.htmlEntities(url) + ' ' + $.PrivateBin.Helper.htmlEntities(postfix) === $.PrivateBin.Helper.urls2links(prefix + url + ' ' + postfix); + return prefix + '' + url + ' ' + postfix === $.PrivateBin.Helper.urls2links(prefix + url + ' ' + postfix); } ); }); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index ba47c27a..843dc6a7 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -72,7 +72,7 @@ endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index 9d66a861..c976ce2f 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -50,7 +50,7 @@ endif; ?> - +