diff --git a/src/core/operations/FromBCD.mjs b/src/core/operations/FromBCD.mjs index 8fa990a4..5be1b911 100644 --- a/src/core/operations/FromBCD.mjs +++ b/src/core/operations/FromBCD.mjs @@ -73,6 +73,9 @@ class FromBCD extends Operation { let output = "", byteArray; + if (encoding === undefined) + throw new OperationError("Invalid encoding scheme"); + // Normalise the input switch (inputFormat) { case "Nibbles": diff --git a/src/core/operations/ToBCD.mjs b/src/core/operations/ToBCD.mjs index 3908742c..4e880400 100644 --- a/src/core/operations/ToBCD.mjs +++ b/src/core/operations/ToBCD.mjs @@ -67,6 +67,9 @@ class ToBCD extends Operation { signed = args[2], outputFormat = args[3]; + if (encoding === undefined) + throw new OperationError("Invalid 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..53d46948 100644 --- a/tests/operations/tests/BCD.mjs +++ b/tests/operations/tests/BCD.mjs @@ -100,4 +100,26 @@ TestRegister.addTests([ } ] }, + { + name: "To BCD: invalid (empty) encoding scheme", + input: "43", + expectedOutput: "Invalid encoding scheme", + recipeConfig: [ + { + "op": "To BCD", + "args": ["", true, false, "Nibbles"] + } + ] + }, + { + name: "From BCD: invalid (empty) encoding scheme", + input: "0100 0011", + expectedOutput: "Invalid encoding scheme", + recipeConfig: [ + { + "op": "From BCD", + "args": ["", true, false, "Nibbles"] + } + ] + }, ]);