Workaround for the faulty link tokenizer in Redactor
authorAlexander Ebert <ebert@woltlab.com>
Mon, 24 Jun 2019 13:52:42 +0000 (15:52 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 24 Jun 2019 13:52:42 +0000 (15:52 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 9e48cf5af53eaaeabc1cd3f5cb4fc9928832a06f..97bb448639437b5935f36067ae5f8fb717f09234 100644 (file)
@@ -421,7 +421,7 @@ $.Redactor.prototype.WoltLabClean = function() {
                                if (data.links && this.opts.pasteLinks) {
                                        elBySelAll('a', div, function(link) {
                                                if (link.href) {
-                                                       link.outerHTML = '#####[a href="' + link.href + '"]#####' + link.innerHTML + '#####[/a]#####';
+                                                       link.outerHTML = '#@###[a href="' + link.href + '"]###@#' + link.innerHTML + '#@###[/a]###@#';
                                                }
                                        });
                                        
@@ -489,6 +489,15 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        
                                        html = div.innerHTML;
                                }
+
+                               // The original code uses a slightly different pattern that did not distinguish between the
+                               // opening and closing "#####" pattern, causing some degree of ambiguity and false-positives.
+                               // links & images
+                               if ((data.links && this.opts.pasteLinks) || (data.images && this.opts.pasteImages))
+                               {
+                                       html = html.replace(new RegExp('#@###\\[', 'gi'), '<');
+                                       html = html.replace(new RegExp('\\]###@#', 'gi'), '>');
+                               }
                                
                                return mpReconvertTags.call(this, html, data);
                        }).bind(this);