From 37783a47ea10ba5928f216273cce47d6e93a664c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 4 Jan 2017 11:18:00 +0100 Subject: [PATCH] Stripping invalid icon classes from editor html input --- .../redactor2/plugins/WoltLabSource.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js index 1471a0c6f4..66ffc4f6a1 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js @@ -24,12 +24,41 @@ $.Redactor.prototype.WoltLabSource = function() { }); }; + function stripIcons(div) { + elBySelAll('.icon, .fa', div, function (element) { + var classNames = element.className.split(' '); + classNames = classNames.filter(function (value) { + if (value === 'fa' || value === 'icon') { + return false; + } + else if (value.match(/^icon\d{2}$/)) { + return false; + } + else if (value.match(/^fa-[a-z\-]+$/)) { + return false; + } + + return true; + }); + + element.className = classNames.join(' '); + if (element.className.trim() === '' && element.innerHTML === '') { + elRemove(element); + } + }); + } + // disable caret position in source mode this.source.setCaretOnShow = function () {}; this.source.setCaretOnHide = function (html) { return html; }; var mpHide = this.source.hide; this.source.hide = (function () { + // use jQuery to parse, its parser is much more graceful + var div = $('
').html(this.source.$textarea.val()); + stripIcons(div[0]); + this.source.$textarea.val(div[0].innerHTML); + mpHide.call(this); setTimeout((function() { -- 2.20.1