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)
This commit is contained in:
min23asdw 2026-03-22 02:00:17 +07:00
parent 78d40eab60
commit ae0e989635
2 changed files with 43 additions and 5 deletions

View File

@ -24,12 +24,17 @@ import Utils from "../Utils.mjs";
* fromDecimal("10:20:30", "Colon"); * fromDecimal("10:20:30", "Colon");
*/ */
export function fromDecimal(data, delim="Auto") { export function fromDecimal(data, delim="Auto") {
let byteStr;
if (delim === "Auto") {
byteStr = data.split(/[^\d-]+/);
} else {
delim = Utils.charRep(delim); delim = Utils.charRep(delim);
const output = []; byteStr = data.split(delim);
let byteStr = data.split(delim); }
if (byteStr[byteStr.length-1] === "")
byteStr = byteStr.slice(0, byteStr.length-1);
byteStr = byteStr.filter(str => str !== "");
const output = [];
for (let i = 0; i < byteStr.length; i++) { for (let i = 0; i < byteStr.length; i++) {
output[i] = parseInt(byteStr[i], 10); output[i] = parseInt(byteStr[i], 10);
} }

View File

@ -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]
},
],
},
]); ]);