[BUGFIX] Prevent duplicate pastes in rtehtmlarea 71/49871/5
authorStefan Froemken <froemken@gmail.com>
Tue, 6 Sep 2016 12:09:01 +0000 (14:09 +0200)
committerJan Helke <typo3@helke.de>
Mon, 24 Oct 2016 15:24:58 +0000 (17:24 +0200)
if pasteFormat or pasteStructur is activated in user settings,
pastings in rtehtmlarea will be inserted twice. Once as plaintext
and a second time as html.
Instead of appending all different text types of ClipBoard
we now override the complete clipboardText, if it is not
of the expected type.
To prevent pasting header data from OpenOffice/LibreOffice/Word
we have added a default value for removeTagsAndContents
which is configurable now.

Resolves: #67661
Releases: master,7.6
Change-Id: I62418ed2d1ce72bb1fb2839e23eaeaa76f42a4c8
Reviewed-on: https://review.typo3.org/49871
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/Plugins/PlainText.js

index 60b57e6..2de9a87 100644 (file)
@@ -85,11 +85,13 @@ define(['TYPO3/CMS/Rtehtmlarea/HTMLArea/Plugin/Plugin',
                cleanerConfig: {
                        pasteStructure: {
                                keepTags: /^(a|p|h[0-6]|pre|address|article|aside|blockquote|div|footer|header|nav|section|hr|br|table|thead|tbody|tfoot|caption|tr|th|td|ul|ol|dl|li|dt|dd)$/i,
-                               removeAttributes: /^(id|on.*|style|class|className|lang|align|valign|bgcolor|color|border|face|.*:.*)$/i
+                               removeAttributes: /^(id|on.*|style|class|className|lang|align|valign|bgcolor|color|border|face|.*:.*)$/i,
+                               removeTagsAndContents: /^(meta|head|title|style)/i
                        },
                        pasteFormat: {
                                keepTags: /^(a|p|h[0-6]|pre|address|article|aside|blockquote|div|footer|header|nav|section|hr|br|img|table|thead|tbody|tfoot|caption|tr|th|td|ul|ol|dl|li|dt|dd|b|bdo|big|cite|code|del|dfn|em|i|ins|kbd|label|q|samp|small|strike|strong|sub|sup|tt|u|var)$/i,
-                               removeAttributes:  /^(id|on.*|style|class|className|lang|align|valign|bgcolor|color|border|face|.*:.*)$/i
+                               removeAttributes:  /^(id|on.*|style|class|className|lang|align|valign|bgcolor|color|border|face|.*:.*)$/i,
+                               removeTagsAndContents: /^(meta|head|title|style)/i
                        }
                },
 
@@ -110,6 +112,9 @@ define(['TYPO3/CMS/Rtehtmlarea/HTMLArea/Plugin/Plugin',
                                        if (this.pasteBehaviourConfiguration[behaviour].removeAttributes) {
                                                this.cleanerConfig[behaviour].removeAttributes = new RegExp( '^(' + this.pasteBehaviourConfiguration[behaviour].removeAttributes.split(',').join('|') + ')$', 'i');
                                        }
+                                       if (this.pasteBehaviourConfiguration[behaviour].removeTagsAndContents) {
+                                               this.cleanerConfig[behaviour].removeTagsAndContents = new RegExp( '^(' + this.pasteBehaviourConfiguration[behaviour].removeTagsAndContents.split(',').join('|') + ')$', 'i');
+                                       }
                                }
                                this.cleaners[behaviour] = new Walker(this.cleanerConfig[behaviour]);
                        }
@@ -320,8 +325,14 @@ define(['TYPO3/CMS/Rtehtmlarea/HTMLArea/Plugin/Plugin',
                                                        var i = 0, contentType;
                                                        while (i < contentTypes.length) {
                                                                contentType = contentTypes[i];
-                                                               if (/text\/plain|text\/html/.test(contentType)) {
-                                                                       clipboardText += clipboardData.getData(contentType);
+                                                               // return clipboardText if is HTML
+                                                               if (/text\/html/.test(contentType)) {
+                                                                       clipboardText = clipboardData.getData(contentType);
+                                                                       break;
+                                                               }
+                                                               // add plainText
+                                                               if (/text\/plain/.test(contentType)) {
+                                                                       clipboardText = clipboardData.getData(contentType);
                                                                }
                                                                i++;
                                                        }