Avoid protocol replacement for valid URLs
authorAlexander Ebert <ebert@woltlab.com>
Wed, 11 Apr 2018 10:18:10 +0000 (12:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 11 Apr 2018 10:18:10 +0000 (12:18 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js

index 9fe94fdd51cdce54bb37bd8abc4c6c2d5e580ff9..de68d1c3fabfe6edbf7afdabbf24894ee0baa72e 100644 (file)
@@ -33,19 +33,26 @@ $.Redactor.prototype.WoltLabLink = function() {
                        
                        this.link.show = this.WoltLabLink.show.bind(this);
                        
-                       var mpParse = this.link.parse;
                        this.link.parse = (function(link) {
-                               var isHttps = false;
-                               if (link.url.match(/^(https:)?\/\//)) {
-                                       isHttps = true;
+                               // mailto
+                               if (this.link.isMailto(link.url))
+                               {
+                                       link.url = 'mailto:' + link.url.replace('mailto:', '');
+                               }
+                               // url
+                               else if (link.url.search('#') !== 0)
+                               {
+                                       if (this.opts.linkValidation)
+                                       {
+                                               var url = this.link.isUrl(link.url);
+                                               if (url === false) url = 'http://' + link.url;
+                                               
+                                               link.url = url;
+                                       }
                                }
                                
-                               link = mpParse.call(this, link);
-                               
-                               // the link validation assumes http:// regardless of the previously set value
-                               if (isHttps) link.url = link.url.replace(/^http:/, 'https:');
-                               
-                               return link;
+                               // empty url or text or isn't url
+                               return (this.link.isEmpty(link) || link.url === false) ? false : link;
                        }).bind(this);
                        
                        require(['WoltLabSuite/Core/Ui/Redactor/Link'], function(UiRedactorLink) {