Incorrect cleanup of pasted tables
authorAlexander Ebert <ebert@woltlab.com>
Sat, 4 Dec 2021 14:24:17 +0000 (15:24 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 4 Dec 2021 14:24:17 +0000 (15:24 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
wcfsetup/install/files/js/3rdParty/redactor2/redactor.js

index f39317056d7e9bab08d3b5a7ec82daa4ac8fef51..3bc6ebb64ba3e4ac02acb8fdc6d748925c6e5d91 100644 (file)
@@ -546,6 +546,26 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        hadImages = true;
                                        data.images = false;
                                }
+
+                               div.querySelectorAll("colgroup").forEach((colgroup) => colgroup.remove());
+
+                               // Clean up attributes in tables because Redactor's regex is bad.
+                               div.querySelectorAll("table, tbody, td, th, thead, tr").forEach((cell) => {
+                                       for (let i = cell.attributes.length - 1; i >= 0; i--) {
+                                               const attr = cell.attributes.item(i);
+                                               const name = attr.name;
+                                               if (cell.nodeName === "TD" || cell.nodeName === "TH") {
+                                                       if (name === "colspan" || name === "rowspan") {
+                                                               const value = +attr.value;
+                                                               if (!Number.isNaN(value) && Number.isInteger(value)) {
+                                                                       continue;
+                                                               }
+                                                       }
+                                               }
+
+                                               cell.attributes.removeNamedItem(name);
+                                       }
+                               });
                                
                                html = mpConvertTags.call(this, div.innerHTML, data);
                                
index 953f9b29b6a5b8e7d42e18356e69b824e3106e07..c590f1d00e5c49b2c9597f76914d165d0c540f02 100644 (file)
                                                
                                                if (tags[i] === 'td' || tags[i] === 'th') {
                                                        html = html.replace(new RegExp(
-                                                               '<' + tags[i] + '(.*?[^>])((colspan|rowspan)="(.*?[^>])")?(.*?[^>])>',
+                                                               '<' + tags[i] + '([^>]*?)>',
                                                                'gi'
-                                                       ), '###' + tags[i] + ' $2###');
+                                                       ), '###' + tags[i] + ' $1###');
                                                }
                                                else if (this.utils.isInlineTag(tags[i])) {
                                                        html = html.replace(