diff --git a/package-lock.json b/package-lock.json index cde26b1484..a8068e3fd9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13610,20 +13610,24 @@ } }, "node_modules/morgan": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.1.tgz", - "integrity": "sha512-223dMRJtI/l25dJKWpgij2cMtywuG/WiUKXdvwfbhGKBhy1puASqXwFzmWZ7+K73vUPoR7SS2Qz2cI/g9MKw0A==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.11.0.tgz", + "integrity": "sha512-zSkVu3t18r39pw4ixfBKvfZi3y2UOqr7d4WYwcj3m8nXpEQK4rPO6GLzs/CExoRgmX3y9EjmmcXqv6jq0SK46g==", "dev": true, "license": "MIT", "dependencies": { "basic-auth": "~2.0.1", "debug": "2.6.9", "depd": "~2.0.0", - "on-finished": "~2.3.0", + "on-finished": "~2.4.1", "on-headers": "~1.1.0" }, "engines": { "node": ">= 0.8.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/morgan/node_modules/debug": { @@ -13643,6 +13647,19 @@ "dev": true, "license": "MIT" }, + "node_modules/morgan/node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "dev": true, + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/mrmime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", diff --git a/src/core/lib/Decimal.mjs b/src/core/lib/Decimal.mjs index a140fd4e6d..e0b36369a1 100644 --- a/src/core/lib/Decimal.mjs +++ b/src/core/lib/Decimal.mjs @@ -24,12 +24,12 @@ 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); + const delimRegex = delim === "Auto" ? /[^\d-]+/ : Utils.regexRep(delim); + let byteStr = data.split(delimRegex); + + byteStr = byteStr.filter(str => str !== ""); + const output = []; for (let i = 0; i < byteStr.length; i++) { output[i] = parseInt(byteStr[i], 10); } diff --git a/src/core/operations/FromDecimal.mjs b/src/core/operations/FromDecimal.mjs index f98931d625..16af47e9e6 100644 --- a/src/core/operations/FromDecimal.mjs +++ b/src/core/operations/FromDecimal.mjs @@ -8,6 +8,11 @@ import Operation from "../Operation.mjs"; import {DELIM_OPTIONS} from "../lib/Delim.mjs"; import {fromDecimal} from "../lib/Decimal.mjs"; +/** + * From Decimal delimiters, plus auto-detection. + */ +const FROM_DECIMAL_DELIM_OPTIONS = [...DELIM_OPTIONS, "Auto"]; + /** * From Decimal operation */ @@ -28,7 +33,7 @@ class FromDecimal extends Operation { { "name": "Delimiter", "type": "option", - "value": DELIM_OPTIONS + "value": FROM_DECIMAL_DELIM_OPTIONS }, { "name": "Support signed values", diff --git a/tests/operations/tests/FromDecimal.mjs b/tests/operations/tests/FromDecimal.mjs index dfc440ec53..a8711840fc 100644 --- a/tests/operations/tests/FromDecimal.mjs +++ b/tests/operations/tests/FromDecimal.mjs @@ -30,4 +30,59 @@ 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] + }, + ], + }, + { + 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] + }, + ], + }, ]);