]> git.mxchange.org Git - friendica.git/commitdiff
Remove unevenly supported lookbehind from link preview regular expression
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 30 Aug 2019 01:12:46 +0000 (21:12 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Fri, 30 Aug 2019 01:12:53 +0000 (21:12 -0400)
- Simplify link preview condition

view/js/linkPreview.js

index 7644af7fee4f37b41ee25eada88458284020ade5..c01856384888418080f483d7faa54f56de1462ca 100644 (file)
@@ -52,7 +52,7 @@
                        <div class="clear"></div>\
                        <hr class="previewseparator">';
                var text;
-               var urlRegex = /(?<!=)(https?\:\/\/|\s)[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})(\/+[a-z0-9_.\:\;-]*)*(\?[\&\%\|\+a-z0-9_=,\.\:\;-]*)?([\&\%\|\+&a-z0-9_=,\:\;\.-]*)([\!\#\/\&\%\|\+a-z0-9_=,\:\;\.-]*)}*/i;
+               var urlRegex = /^(?:https?\:\/\/|\s)[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})(?:\/+[a-z0-9_.\:\;-]*)*(?:\?[\&\%\|\+a-z0-9_=,\.\:\;-]*)?(?:[\&\%\|\+&a-z0-9_=,\:\;\.-]*)(?:[\!\#\/\&\%\|\+a-z0-9_=,\:\;\.-]*)}*$/i;
                var binurl;
                var block = false;
                var blockTitle = false;
                                return;
                        }
 
-                       if (trim(text) !== "") {
-                               if (block === false && urlRegex.test(text)) {
-                                       binurl = bin2hex(text);
-                                       block = true;
+                       if (trim(text) !== "" && block === false && urlRegex.test(text)) {
+                               binurl = bin2hex(text);
+                               block = true;
 
-                                       isCrawling = true;
-                                       $('#profile-rotator').show();
+                               isCrawling = true;
+                               $('#profile-rotator').show();
 
-                                       if (binurl in cache) {
-                                               isCrawling = false;
-                                               processContentData(cache[binurl]);
-                                       } else {
-                                               getContentData(binurl, processContentData);
-                                       }
+                               if (binurl in cache) {
+                                       isCrawling = false;
+                                       processContentData(cache[binurl]);
+                               } else {
+                                       getContentData(binurl, processContentData);
                                }
                        }
                };