Convert model attributes to strings for comparison
authorAlexander Ebert <ebert@woltlab.com>
Wed, 9 Aug 2023 13:27:46 +0000 (15:27 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 9 Aug 2023 13:27:46 +0000 (15:27 +0200)
The editor API does not guarantee the attribute types to be preserved, numbers can be converted into strings and returned as such.

See https://www.woltlab.com/community/thread/300956-deleted-attachments-do-not-disappear-from-the-editor/

ts/WoltLabSuite/Core/Component/Ckeditor.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js

index 2a65989e9c7db62a118f82e9a64f8454a4ba10ae..da7178b5054f494e2434af2729969e2132e69bbb 100644 (file)
@@ -143,11 +143,12 @@ function* findModelForRemoval(
   attributes: Record<string, string | number | boolean>,
 ): Generator<CkeElement> {
   if (element.is("element", model)) {
-    let isMatch = true;
-    Object.entries(attributes).forEach(([key, value]) => {
+    const isMatch = Object.entries(attributes).every(([key, value]) => {
       if (!element.hasAttribute(key)) {
-        isMatch = false;
-      } else if (element.getAttribute(key) !== value) isMatch = false;
+        return false;
+      }
+
+      return String(element.getAttribute(key)) === value.toString();
     });
 
     if (isMatch) {
index dee83237cc3e69f96418392502d957a2421aa65a..7dbfa6f9ac1fd28f2e64d896c1dd0aaa47af0cc9 100644 (file)
@@ -106,13 +106,11 @@ define(["require", "exports", "tslib", "./Ckeditor/Attachment", "./Ckeditor/Medi
     }
     function* findModelForRemoval(element, model, attributes) {
         if (element.is("element", model)) {
-            let isMatch = true;
-            Object.entries(attributes).forEach(([key, value]) => {
+            const isMatch = Object.entries(attributes).every(([key, value]) => {
                 if (!element.hasAttribute(key)) {
-                    isMatch = false;
+                    return false;
                 }
-                else if (element.getAttribute(key) !== value)
-                    isMatch = false;
+                return String(element.getAttribute(key)) === value.toString();
             });
             if (isMatch) {
                 yield element;