Block the submission of invalid color values.
authorAlexander Ebert <ebert@woltlab.com>
Thu, 16 Nov 2023 15:32:56 +0000 (16:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 16 Nov 2023 15:32:56 +0000 (16:32 +0100)
See https://www.woltlab.com/community/thread/302477-stil-editor-bei-ung%C3%BCltiger-farbe-fehlermeldung/

ts/WoltLabSuite/Core/Ui/Color/Picker.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Color/Picker.js

index 3ef0470bfcad1cfa923a5cc00f3aa9b591afaafb..e42372471eb89619cde9db87713e70fe9d6b7130 100644 (file)
@@ -345,6 +345,12 @@ class UiColorPicker implements DialogCallbackObject {
    */
   protected submitDialog(): void {
     const color = this.getColor(ColorSource.RGBA);
+    const hasNanValue = Object.values(color).some((value) => Number.isNaN(value));
+    if (hasNanValue) {
+      // Prevent the submission of invalid color values.
+      return;
+    }
+
     const colorString = ColorUtil.rgbaToString(color);
 
     this.oldColor!.style.backgroundColor = colorString;
index 69dd6b9d2ae3d6b6516e8de20c9d4443033cad15..3ab78f29276aa08cf3f2d84556c08176d847fda6 100644 (file)
@@ -274,6 +274,11 @@ define(["require", "exports", "tslib", "../../Core", "../Dialog", "../../Dom/Uti
          */
         submitDialog() {
             const color = this.getColor("rgba" /* ColorSource.RGBA */);
+            const hasNanValue = Object.values(color).some((value) => Number.isNaN(value));
+            if (hasNanValue) {
+                // Prevent the submission of invalid color values.
+                return;
+            }
             const colorString = ColorUtil.rgbaToString(color);
             this.oldColor.style.backgroundColor = colorString;
             this.input.value = colorString;