fix: fromDecimal Auto delimiter now correctly parses multiple numbers#2270
Open
min23asdw wants to merge 9 commits intogchq:masterfrom
Open
fix: fromDecimal Auto delimiter now correctly parses multiple numbers#2270min23asdw wants to merge 9 commits intogchq:masterfrom
min23asdw wants to merge 9 commits intogchq:masterfrom
Conversation
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 gchq#2217
Ref: gchq#2221 (closed due to unsigned CLA)
Covers additional edge cases for the Auto delimiter fix: - newline-separated input - signed (negative) values with Auto delimiter Ref: gchq#2217
GCHQDeveloper581
requested changes
Mar 22, 2026
3 tasks
Author
|
I add "Auto" (not default) mode in dropdown's From Decimal. Without this, the Auto regex in fromDecimal() is unreachable 2026-03-23.16-12-29.mp4 |
Author
|
@GCHQDeveloper581 would you mind if it shold have 'FROM_DECIMAL_DELIM_OPTIONS' becase if it don't have #2270 (comment) 'auto' mode it will can't not access by UI, cc #2308 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #2217
Ref: #2221 (closed due to unsigned CLA)
Description
fromDecimal()did not correctly handle thedelimparameter when set to"Auto".Root cause:
Utils.charRep("Auto")returnsundefined(no "Auto" entry in the mapping), sodata.split(undefined)returns the entire string as a single array element — only the first number gets parsed.Fix: When
delim === "Auto", split on regex/[^\d-]+/(any non-digit, non-minus characters), consistent with howfromHex()handles its Auto delimiter. Existing delimiter behavior is unchanged.Changes
src/core/lib/Decimal.mjs— Auto delimiter uses regex split instead ofUtils.charReptests/operations/tests/FromDecimal.mjs— Added 5 test cases for Auto delimiter (space, comma, mixed, newline, signed values)Before / After
"72 101 108 108 111"(Auto)[72]→"H"[72,101,108,108,111]→"Hello""72,101,108,108,111"(Auto)[72]→"H"[72,101,108,108,111]→"Hello""72, 101 : 108; 108\t111"(Auto)[72]→"H"[72,101,108,108,111]→"Hello"Verification
npx grunt lint— all tasks passNote on edge cases
Two edge cases with malformed input were tested — neither is a security concern:
"--1"[NaN]parseInt("--1")returnsNaN. This is consistent with garbage-in, garbage-out behavior."72;alert(1);101"[72, 1, 101]alert(as a delimiter, so the1inside the parentheses is parsed as a number. No code execution occurs —fromDecimalonly produces an integer array viaparseInt. This matchesfromHexAuto behavior.▎ This pull request was created with the assistance of Claude and Antigravity, to suggest ideas on where it might be broken and to help write the tests. then searched online to verify whether those suggestions were correct.
I have reviewed and tested all code changes. All changes were manually verified.