From dc08dc582ddb3f5675e4cae80bb428f976f2f15c Mon Sep 17 00:00:00 2001 From: marko1olo Date: Sat, 6 Jun 2026 03:58:14 +0400 Subject: [PATCH] Fix To Base radix validation --- src/core/operations/ToBase.mjs | 2 +- tests/operations/index.mjs | 1 + tests/operations/tests/Base.mjs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/operations/tests/Base.mjs diff --git a/src/core/operations/ToBase.mjs b/src/core/operations/ToBase.mjs index 09a91571..53f5eff1 100644 --- a/src/core/operations/ToBase.mjs +++ b/src/core/operations/ToBase.mjs @@ -43,7 +43,7 @@ class ToBase extends Operation { throw new OperationError("Error: Input must be a number"); } const radix = args[0]; - if (radix < 2 || radix > 36) { + if (!Number.isInteger(radix) || radix < 2 || radix > 36) { throw new OperationError("Error: Radix argument must be between 2 and 36"); } return input.toString(radix); diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index 44792560..7feba513 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -21,6 +21,7 @@ import "./tests/AnalyseUUID.mjs"; import "./tests/AlternatingCaps.mjs"; import "./tests/AvroToJSON.mjs"; import "./tests/BaconCipher.mjs"; +import "./tests/Base.mjs"; import "./tests/Base32.mjs"; import "./tests/Base45.mjs"; import "./tests/Base58.mjs"; diff --git a/tests/operations/tests/Base.mjs b/tests/operations/tests/Base.mjs new file mode 100644 index 00000000..d173db91 --- /dev/null +++ b/tests/operations/tests/Base.mjs @@ -0,0 +1,33 @@ +/** + * Base conversion tests + * + * @author marko1olo + * @copyright Crown Copyright 2026 + * @license Apache-2.0 + */ +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "To Base: base 2", + input: "63", + expectedOutput: "111111", + recipeConfig: [ + { + "op": "To Base", + "args": [2] + } + ] + }, + { + name: "To Base: fractional radix", + input: "63", + expectedOutput: "Error: Radix argument must be between 2 and 36", + recipeConfig: [ + { + "op": "To Base", + "args": [2.2] + } + ] + }, +]);