From 759febdf533acba401bc1e0a758328e0857e727c Mon Sep 17 00:00:00 2001 From: Philip Le Riche <7701190+p-leriche@users.noreply.github.com> Date: Sat, 7 Mar 2026 19:16:40 +0000 Subject: [PATCH] Add error handling for Unicode characters beyond Latin-1 and test for Latin-1 accepted --- src/core/operations/TextIntegerConverter.mjs | 11 ++++++++++- .../operations/tests/TextIntegerConverter.mjs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/operations/TextIntegerConverter.mjs b/src/core/operations/TextIntegerConverter.mjs index e7ff4547..4e740100 100644 --- a/src/core/operations/TextIntegerConverter.mjs +++ b/src/core/operations/TextIntegerConverter.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; /* ---------- helper functions ---------- */ @@ -17,6 +18,11 @@ function textToBigInt(text) { let result = 0n; for (let i = 0; i < text.length; i++) { const charCode = BigInt(text.charCodeAt(i)); + if (charCode > 255n) { + throw new OperationError( + `Character at position ${i} exceeds Latin-1 range (0-255).\n` + + "Only ASCII and Latin-1 characters are supported."); + } result = (result << 8n) | charCode; } return result; @@ -58,7 +64,10 @@ class TextIntegerConverter extends Operation { "Input format detection:
" + "Decimal: digits 0-9 only
" + "Hexadecimal: 0x... prefix
" + - "Quoted or unquoted text: treated as string

" ; + "Quoted or unquoted text: treated as string

" + + "Character limitations:
" + + "Text input may only contain ASCII and Latin-1 characters (code point < 256).
" + + "Multi-byte Unicode characters will generate an error.

." ; this.infoURL = "https://wikipedia.org/wiki/Endianness"; this.inputType = "string"; this.outputType = "string"; diff --git a/tests/operations/tests/TextIntegerConverter.mjs b/tests/operations/tests/TextIntegerConverter.mjs index 17466564..d05aa24a 100644 --- a/tests/operations/tests/TextIntegerConverter.mjs +++ b/tests/operations/tests/TextIntegerConverter.mjs @@ -94,6 +94,25 @@ TestRegister.addTests([ }, ], }, + { + name: "Text-Integer Conversion implicit round trip string-string Latin-1", + input: "U+00FF", + expectedOutput: "U+00FF", // U+00FF (Latin small letter y with diaeresis) + recipeConfig: [ + { + op: "Unescape Unicode Characters", + args: ["U+"], + }, + { + op: "Text-Integer Conversion", + args: ["String"], + }, + { + op: "Escape Unicode Characters", + args: ["U+", false, 4, true], + }, + ], + }, { name: "Text-Integer Conversion unquoted text to decimal", input: "Hi",