From a7acad4211a6e2df44d7433b337045c1422c4544 Mon Sep 17 00:00:00 2001 From: Kairos Ops <186839917+KairosOps@users.noreply.github.com> Date: Sun, 21 Jun 2026 07:22:26 +0800 Subject: [PATCH] Validate View Bit Plane colour input --- src/core/operations/ViewBitPlane.mjs | 6 ++++++ tests/operations/tests/Image.mjs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/core/operations/ViewBitPlane.mjs b/src/core/operations/ViewBitPlane.mjs index 3740c10d78..b9d03fb23d 100644 --- a/src/core/operations/ViewBitPlane.mjs +++ b/src/core/operations/ViewBitPlane.mjs @@ -59,6 +59,12 @@ class ViewBitPlane extends Operation { colourIndex = COLOUR_OPTIONS.indexOf(colour), bitIndex = 7 - bit; + if (colourIndex === -1) { + throw new OperationError( + `Error: Colour argument must be one of ${COLOUR_OPTIONS.join(", ")}`, + ); + } + if (bit < 0 || bit > 7) { throw new OperationError( "Error: Bit argument must be between 0 and 7", diff --git a/tests/operations/tests/Image.mjs b/tests/operations/tests/Image.mjs index 1f45043340..d162a39db5 100644 --- a/tests/operations/tests/Image.mjs +++ b/tests/operations/tests/Image.mjs @@ -230,6 +230,21 @@ TestRegister.addTests([ } ] }, + { + name: "View Bit Plane: invalid colour", + input: PNG_HEX, + expectedOutput: "Error: Colour argument must be one of Red, Green, Blue, Alpha", + recipeConfig: [ + { + op: "From Hex", + args: ["None"] + }, + { + op: "View Bit Plane", + args: ["", 7] + }, + ], + }, { name: "Randomize Colour Palette", "input": PNG_HEX,