From 324a23585e5a707221e79066b1ddcadf371d355a Mon Sep 17 00:00:00 2001 From: Benjamin Eriksson Date: Wed, 11 Feb 2026 10:20:08 +0100 Subject: [PATCH] Fixed Percent delimiter for hex encoding (#2137) Co-authored-by: GCHQ Developer 85297 <95289555+C85297@users.noreply.github.com> --- src/core/lib/Hex.mjs | 2 +- tests/operations/tests/Hex.mjs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 78e1ad58..6f998e2b 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -33,7 +33,7 @@ export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) { if (data instanceof ArrayBuffer) data = new Uint8Array(data); let output = ""; - const prepend = (delim === "0x" || delim === "\\x"); + const prepend = (delim === "0x" || delim === "\\x" || delim === "%"); for (let i = 0; i < data.length; i++) { const hex = data[i].toString(16).padStart(padding, "0"); diff --git a/tests/operations/tests/Hex.mjs b/tests/operations/tests/Hex.mjs index 3bb89544..6e49f6f8 100644 --- a/tests/operations/tests/Hex.mjs +++ b/tests/operations/tests/Hex.mjs @@ -43,6 +43,20 @@ TestRegister.addTests([ } ] }, + { + name: "ASCII to Hex with percent deliminator", + input: "aberystwyth", + expectedOutput: "%61%62%65%72%79%73%74%77%79%74%68", + recipeConfig: [ + { + "op": "To Hex", + "args": [ + "Percent", + 0 + ] + } + ] + }, { name: "ASCII to 0x Hex with comma and line breaks", input: "aberystwyth",