Prevent Redactor from interefering with text pasted into plaintext blocks
authorAlexander Ebert <ebert@woltlab.com>
Mon, 4 Dec 2017 13:00:51 +0000 (14:00 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 4 Dec 2017 13:00:51 +0000 (14:00 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 33cf7f26cc0951378c081fcda344fe17b71d70cc..044a18d7344af9644b400eb1d89d43079bcafe99 100644 (file)
@@ -121,15 +121,13 @@ $.Redactor.prototype.WoltLabClean = function() {
                        var mpOnPaste = this.clean.onPaste;
                        this.clean.onPaste = (function (html, data, insert) {
                                if (data.pre || this.utils.isCurrentOrParent('kbd')) {
-                                       // prevent method call when data.pre is true
-                                       var mpRemoveEmptyInlineTags = this.clean.removeEmptyInlineTags;
-                                       this.clean.removeEmptyInlineTags = function(html) { return html; };
-                                       
-                                       html = mpOnPaste.call(this, html, data, insert);
-                                       
-                                       this.clean.removeEmptyInlineTags = mpRemoveEmptyInlineTags;
+                                       // instead of calling the original method, we'll use a subset of the cleaning
+                                       // tasks in order to avoid malformed HTML being sanitized by Redactor
+                                       if (data.pre && this.opts.preSpaces) {
+                                               html = html.replace(/\t/g, new Array(this.opts.preSpaces + 1).join(' '));
+                                       }
                                        
-                                       return html;
+                                       return WCF.String.escapeHTML(html);
                                }
                                
                                var div = elCreate('div');