diff --git a/src/core/lib/Modhex.mjs b/src/core/lib/Modhex.mjs index 4f28e9a11..ab4a7c8bb 100644 --- a/src/core/lib/Modhex.mjs +++ b/src/core/lib/Modhex.mjs @@ -50,6 +50,7 @@ const HEX_ALPHABET_MAP = HEX_ALPHABET.split(""); export function toModhex(data, delim=" ", padding=2, extraDelim="", lineSize=0) { if (!data) return ""; if (data instanceof ArrayBuffer) data = new Uint8Array(data); + if (data.length === 0) return ""; const regularHexString = toHex(data, "", padding, "", 0); @@ -100,6 +101,7 @@ export function toModhex(data, delim=" ", padding=2, extraDelim="", lineSize=0) export function toModhexFast(data) { if (!data) return ""; if (data instanceof ArrayBuffer) data = new Uint8Array(data); + if (data.length === 0) return ""; const output = []; diff --git a/tests/operations/tests/Modhex.mjs b/tests/operations/tests/Modhex.mjs index 1e0f27912..07f38910c 100644 --- a/tests/operations/tests/Modhex.mjs +++ b/tests/operations/tests/Modhex.mjs @@ -147,4 +147,24 @@ dc;ii;hv;ig;hr;hf;dc;he;hj;hv;hv;ie;hg;du", } ] }, + { + name: "Empty input through From Hex and To Modhex returns empty output", + input: "", + expectedOutput: "", + recipeConfig: [ + { + "op": "From Hex", + "args": [ + "Auto" + ] + }, + { + "op": "To Modhex", + "args": [ + "Space", + 0 + ] + } + ] + }, ]);