From: Alexander Ebert Date: Wed, 4 Jan 2017 10:18:00 +0000 (+0100) Subject: Stripping invalid icon classes from editor html input X-Git-Tag: 3.0.0~63 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=37783a47ea10ba5928f216273cce47d6e93a664c;p=GitHub%2FWoltLab%2FWCF.git Stripping invalid icon classes from editor html input --- 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() {