From ae0e9896350fe40b313a316d68e0b78ac52f5c91 Mon Sep 17 00:00:00 2001 From: min23asdw Date: Sun, 22 Mar 2026 02:00:17 +0700 Subject: [PATCH 1/4] fix: handle Auto delimiter correctly in fromDecimal When delim is "Auto", Utils.charRep("Auto") returns undefined, causing data.split(undefined) to return the entire string as a single element. This meant only the first number was parsed. Fix by splitting on a regex /[^\d-]+/ for Auto mode, consistent with how fromHex handles its Auto delimiter. Existing delimiter behavior is unchanged. Adds test cases for Auto delimiter with space, comma, and mixed separators. Fixes #2217 Ref: #2221 (closed due to unsigned CLA) --- src/core/lib/Decimal.mjs | 15 ++++++++---- tests/operations/tests/FromDecimal.mjs | 33 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/core/lib/Decimal.mjs b/src/core/lib/Decimal.mjs index a140fd4e6d..cf93257b74 100644 --- a/src/core/lib/Decimal.mjs +++ b/src/core/lib/Decimal.mjs @@ -24,12 +24,17 @@ import Utils from "../Utils.mjs"; * fromDecimal("10:20:30", "Colon"); */ export function fromDecimal(data, delim="Auto") { - delim = Utils.charRep(delim); - const output = []; - let byteStr = data.split(delim); - if (byteStr[byteStr.length-1] === "") - byteStr = byteStr.slice(0, byteStr.length-1); + let byteStr; + if (delim === "Auto") { + byteStr = data.split(/[^\d-]+/); + } else { + delim = Utils.charRep(delim); + byteStr = data.split(delim); + } + byteStr = byteStr.filter(str => str !== ""); + + const output = []; for (let i = 0; i < byteStr.length; i++) { output[i] = parseInt(byteStr[i], 10); } diff --git a/tests/operations/tests/FromDecimal.mjs b/tests/operations/tests/FromDecimal.mjs index dfc440ec53..b94e1cd83f 100644 --- a/tests/operations/tests/FromDecimal.mjs +++ b/tests/operations/tests/FromDecimal.mjs @@ -30,4 +30,37 @@ TestRegister.addTests([ }, ], }, + { + name: "From Decimal with Auto delimiter (space)", + input: "72 101 108 108 111", + expectedOutput: "Hello", + recipeConfig: [ + { + op: "From Decimal", + args: ["Auto", false] + }, + ], + }, + { + name: "From Decimal with Auto delimiter (comma)", + input: "72,101,108,108,111", + expectedOutput: "Hello", + recipeConfig: [ + { + op: "From Decimal", + args: ["Auto", false] + }, + ], + }, + { + name: "From Decimal with Auto delimiter (mixed)", + input: "72, 101 : 108; 108\t111", + expectedOutput: "Hello", + recipeConfig: [ + { + op: "From Decimal", + args: ["Auto", false] + }, + ], + }, ]); From d09ba82159c62c529aaae9ad836d3baf41417c58 Mon Sep 17 00:00:00 2001 From: min23asdw Date: Sun, 22 Mar 2026 02:10:42 +0700 Subject: [PATCH 2/4] test: add Auto delimiter tests for newline and signed values Covers additional edge cases for the Auto delimiter fix: - newline-separated input - signed (negative) values with Auto delimiter Ref: #2217 --- tests/operations/tests/FromDecimal.mjs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/operations/tests/FromDecimal.mjs b/tests/operations/tests/FromDecimal.mjs index b94e1cd83f..a8711840fc 100644 --- a/tests/operations/tests/FromDecimal.mjs +++ b/tests/operations/tests/FromDecimal.mjs @@ -63,4 +63,26 @@ TestRegister.addTests([ }, ], }, + { + name: "From Decimal with Auto delimiter (newline)", + input: "72\n101\n108\n108\n111", + expectedOutput: "Hello", + recipeConfig: [ + { + op: "From Decimal", + args: ["Auto", false] + }, + ], + }, + { + name: "From Decimal with Auto delimiter and signed values", + input: "-130 -140 -152 -151 115 33 0 -1", + expectedOutput: "~this!\u0000\u00ff", + recipeConfig: [ + { + op: "From Decimal", + args: ["Auto", true] + }, + ], + }, ]); From 7d522416a747923ff6dc656de52739a5e157e3f5 Mon Sep 17 00:00:00 2001 From: min23asdw Date: Mon, 23 Mar 2026 15:33:14 +0700 Subject: [PATCH 3/4] use ternary + regexRep pattern matching Hex.mjs --- src/core/lib/Decimal.mjs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/core/lib/Decimal.mjs b/src/core/lib/Decimal.mjs index cf93257b74..e0b36369a1 100644 --- a/src/core/lib/Decimal.mjs +++ b/src/core/lib/Decimal.mjs @@ -24,13 +24,8 @@ import Utils from "../Utils.mjs"; * fromDecimal("10:20:30", "Colon"); */ export function fromDecimal(data, delim="Auto") { - let byteStr; - if (delim === "Auto") { - byteStr = data.split(/[^\d-]+/); - } else { - delim = Utils.charRep(delim); - byteStr = data.split(delim); - } + const delimRegex = delim === "Auto" ? /[^\d-]+/ : Utils.regexRep(delim); + let byteStr = data.split(delimRegex); byteStr = byteStr.filter(str => str !== ""); From 7d971234efae1fa36dcac92cfe1b3b69724a63a9 Mon Sep 17 00:00:00 2001 From: min23asdw Date: Mon, 23 Mar 2026 16:17:36 +0700 Subject: [PATCH 4/4] feat: add Auto delimiter option to From Decimal operation --- src/core/lib/Decimal.mjs | 7 +++++++ src/core/operations/FromDecimal.mjs | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/lib/Decimal.mjs b/src/core/lib/Decimal.mjs index e0b36369a1..3d81695eda 100644 --- a/src/core/lib/Decimal.mjs +++ b/src/core/lib/Decimal.mjs @@ -7,6 +7,7 @@ */ import Utils from "../Utils.mjs"; +import {DELIM_OPTIONS} from "./Delim.mjs"; /** @@ -35,3 +36,9 @@ export function fromDecimal(data, delim="Auto") { } return output; } + + +/** + * From Decimal delimiters. + */ +export const FROM_DECIMAL_DELIM_OPTIONS = [...DELIM_OPTIONS, "Auto"]; diff --git a/src/core/operations/FromDecimal.mjs b/src/core/operations/FromDecimal.mjs index f98931d625..83353074a6 100644 --- a/src/core/operations/FromDecimal.mjs +++ b/src/core/operations/FromDecimal.mjs @@ -5,8 +5,7 @@ */ import Operation from "../Operation.mjs"; -import {DELIM_OPTIONS} from "../lib/Delim.mjs"; -import {fromDecimal} from "../lib/Decimal.mjs"; +import {fromDecimal, FROM_DECIMAL_DELIM_OPTIONS} from "../lib/Decimal.mjs"; /** * From Decimal operation @@ -28,7 +27,7 @@ class FromDecimal extends Operation { { "name": "Delimiter", "type": "option", - "value": DELIM_OPTIONS + "value": FROM_DECIMAL_DELIM_OPTIONS }, { "name": "Support signed values",