Add error handling for Unicode characters beyond Latin-1 and test for Latin-1 accepted
This commit is contained in:
parent
19368b2911
commit
759febdf53
@ -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 {
|
||||
"<b>Input format detection:</b><br>" +
|
||||
"Decimal: digits 0-9 only<br>" +
|
||||
"Hexadecimal: 0x... prefix<br>" +
|
||||
"Quoted or unquoted text: treated as string<br><br>" ;
|
||||
"Quoted or unquoted text: treated as string<br><br>" +
|
||||
"<b>Character limitations:</b><br>" +
|
||||
"Text input may only contain ASCII and Latin-1 characters (code point < 256).<br>" +
|
||||
"Multi-byte Unicode characters will generate an error.<br><br>." ;
|
||||
this.infoURL = "https://wikipedia.org/wiki/Endianness";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user