From ff63ec97b75706b7e12442c7c814e96c89f2db55 Mon Sep 17 00:00:00 2001 From: Sascha Buehrle <47737812+saschabuehrle@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:26:09 +0100 Subject: [PATCH] fix: return empty output for zero-length To Modhex input (#2249) --- src/core/lib/Modhex.mjs | 2 ++ tests/operations/tests/Modhex.mjs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) 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 + ] + } + ] + }, ]);