Просмотр исходного кода

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

This reverts commit 5340f417e07fdfdab2f91f5171f4f992bc763a73.
El RIDO 6 лет назад
Родитель
Сommit
8a6dcf910a
4 измененных файлов с 13 добавлено и 25 удалено
  1. 4 19
      js/privatebin.js
  2. 7 4
      js/test/Helper.js
  3. 1 1
      tpl/bootstrap.php
  4. 1 1
      tpl/page.php

+ 4 - 19
js/privatebin.js

@@ -297,25 +297,10 @@ jQuery.PrivateBin = (function($, RawDeflate) {
          */
          */
         me.urls2links = function(html)
         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 '<a href="' + decodedUrl + '" rel="nofollow">' + encodedUrl + '</a>';
-                        }
-                     )
+            return html.replace(
+                /(((https?|ftp):\/\/[\w?!=&.\/-;#@~%+*-]+(?![\w\s?!&.\/;#~%"=-]*>))|((magnet):[\w?=&.\/-;#@~%+*-]+))/ig,
+                '<a href="$1" rel="nofollow">$1</a>'
+            );
         };
         };
 
 
         /**
         /**

+ 7 - 4
js/test/Helper.js

@@ -81,7 +81,7 @@ describe('Helper', function () {
             'ignores non-URL content',
             'ignores non-URL content',
             'string',
             'string',
             function (content) {
             function (content) {
-                return $.PrivateBin.Helper.htmlEntities(content) === $.PrivateBin.Helper.urls2links(content);
+                return content === $.PrivateBin.Helper.urls2links(content);
             }
             }
         );
         );
         jsc.property(
         jsc.property(
@@ -95,7 +95,8 @@ describe('Helper', function () {
             function (prefix, schema, address, query, fragment, postfix) {
             function (prefix, schema, address, query, fragment, postfix) {
                 query    = query.join('');
                 query    = query.join('');
                 fragment = fragment.join('');
                 fragment = fragment.join('');
-                postfix  = ' ' + postfix;
+                prefix   = $.PrivateBin.Helper.htmlEntities(prefix);
+                postfix  = ' ' + $.PrivateBin.Helper.htmlEntities(postfix);
                 let url  = schema + '://' + address.join('') + '/?' + query + '#' + fragment;
                 let url  = schema + '://' + address.join('') + '/?' + query + '#' + fragment;
 
 
                 // special cases: When the query string and fragment imply the beginning of an HTML entity, eg. &#0 or &#x
                 // special cases: When the query string and fragment imply the beginning of an HTML entity, eg. &#0 or &#x
@@ -108,7 +109,7 @@ describe('Helper', function () {
                     postfix = '';
                     postfix = '';
                 }
                 }
 
 
-                return $.PrivateBin.Helper.htmlEntities(prefix) + '<a href="' + url + '" rel="nofollow">' + $.PrivateBin.Helper.htmlEntities(url) + '</a>' + $.PrivateBin.Helper.htmlEntities(postfix) === $.PrivateBin.Helper.urls2links(prefix + url + postfix);
+                return prefix + '<a href="' + url + '" rel="nofollow">' + url + '</a>' + postfix === $.PrivateBin.Helper.urls2links(prefix + url + postfix);
             }
             }
         );
         );
         jsc.property(
         jsc.property(
@@ -117,8 +118,10 @@ describe('Helper', function () {
             jsc.array(common.jscQueryString()),
             jsc.array(common.jscQueryString()),
             'string',
             'string',
             function (prefix, query, postfix) {
             function (prefix, query, postfix) {
+                prefix   = $.PrivateBin.Helper.htmlEntities(prefix);
+                postfix  = $.PrivateBin.Helper.htmlEntities(postfix);
                 let url  = 'magnet:?' + query.join('').replace(/^&+|&+$/gm,'');
                 let url  = 'magnet:?' + query.join('').replace(/^&+|&+$/gm,'');
-                return $.PrivateBin.Helper.htmlEntities(prefix) + '<a href="' + url + '" rel="nofollow">' + $.PrivateBin.Helper.htmlEntities(url) + '</a> ' + $.PrivateBin.Helper.htmlEntities(postfix) === $.PrivateBin.Helper.urls2links(prefix + url + ' ' + postfix);
+                return prefix + '<a href="' + url + '" rel="nofollow">' + url + '</a> ' + postfix === $.PrivateBin.Helper.urls2links(prefix + url + ' ' + postfix);
             }
             }
         );
         );
     });
     });

+ 1 - 1
tpl/bootstrap.php

@@ -72,7 +72,7 @@ endif;
 ?>
 ?>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
-		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-TJnv+hN/muDppfHqKPn8WDN9DTIlzrizLc283g/1wfJ/gS8Lk9x5fBebAPApPoVPasryUgkh3xPJ0ptImT6jbQ==" crossorigin="anonymous"></script>
+		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-YrCefSac8MOPuEvP3IJTSt6svl0P34qwnFy6czhtOJ6yN6ykmmrFdXKWMmD/gyp+hBnFdQnkC7o3GtrjuZkZgA==" crossorigin="anonymous"></script>
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-16x16.png?<?php echo rawurlencode($VERSION); ?>" sizes="16x16" />
 		<link rel="icon" type="image/png" href="img/favicon-16x16.png?<?php echo rawurlencode($VERSION); ?>" sizes="16x16" />

+ 1 - 1
tpl/page.php

@@ -50,7 +50,7 @@ endif;
 ?>
 ?>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
-		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-TJnv+hN/muDppfHqKPn8WDN9DTIlzrizLc283g/1wfJ/gS8Lk9x5fBebAPApPoVPasryUgkh3xPJ0ptImT6jbQ==" crossorigin="anonymous"></script>
+		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-YrCefSac8MOPuEvP3IJTSt6svl0P34qwnFy6czhtOJ6yN6ykmmrFdXKWMmD/gyp+hBnFdQnkC7o3GtrjuZkZgA==" crossorigin="anonymous"></script>
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-16x16.png?<?php echo rawurlencode($VERSION); ?>" sizes="16x16" />
 		<link rel="icon" type="image/png" href="img/favicon-16x16.png?<?php echo rawurlencode($VERSION); ?>" sizes="16x16" />