From 44b7d045cdffb93e6b388022a2caaf72349847ee Mon Sep 17 00:00:00 2001 From: Deepak kudi Date: Thu, 4 Jun 2026 15:19:03 +0530 Subject: [PATCH] fix: validate To BCD scheme option --- src/core/operations/ToBCD.mjs | 4 ++++ tests/operations/tests/BCD.mjs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/operations/ToBCD.mjs b/src/core/operations/ToBCD.mjs index 3908742c..d8de7da6 100644 --- a/src/core/operations/ToBCD.mjs +++ b/src/core/operations/ToBCD.mjs @@ -67,6 +67,10 @@ class ToBCD extends Operation { signed = args[2], outputFormat = args[3]; + if (!encoding) { + throw new OperationError("Invalid BCD encoding scheme"); + } + // Split input number up into separate digits const digits = input.toFixed().split(""); diff --git a/tests/operations/tests/BCD.mjs b/tests/operations/tests/BCD.mjs index c6715e56..a9e1e344 100644 --- a/tests/operations/tests/BCD.mjs +++ b/tests/operations/tests/BCD.mjs @@ -52,6 +52,17 @@ TestRegister.addTests([ } ] }, + { + name: "To BCD: invalid scheme", + input: "43", + expectedOutput: "Invalid BCD encoding scheme", + recipeConfig: [ + { + "op": "To BCD", + "args": ["", true, false, "Nibbles"] + } + ] + }, { name: "From BCD: default 0", input: "0000",