From ad123a040988b18a83cfb0957d5abedcf8ebb15a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 24 Jun 2019 15:52:42 +0200 Subject: [PATCH] Workaround for the faulty link tokenizer in Redactor --- .../js/3rdParty/redactor2/plugins/WoltLabClean.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index 9e48cf5af5..97bb448639 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -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); -- 2.20.1