Fix median sort, set-op duplicates, and Unescape Unicode range (#2239, #2241, #2242)#2457
Open
vigneshrajan94 wants to merge 1 commit into
Open
Fix median sort, set-op duplicates, and Unescape Unicode range (#2239, #2241, #2242)#2457vigneshrajan94 wants to merge 1 commit into
vigneshrajan94 wants to merge 1 commit into
Conversation
Fixes three independent bugs: - Arithmetic.mjs (median): sort was only applied for even-length arrays; odd-length inputs returned the middle element of the unsorted array. Sort is now unconditional. Fixes gchq#2239. - SetDifference / SetIntersection: plain .filter() on array a preserved duplicate entries from the first input, violating set semantics. Deduplicate a via [...new Set(a)] before filtering. Fixes gchq#2241. - UnescapeUnicodeCharacters: regex quantifier was hardcoded to {4} for all prefixes. U+ notation allows 4-6 hex digits (e.g. U+1F600 for 😀); \u and %u remain at exactly {4} per their respective specs. Fixes gchq#2242.
This was referenced May 27, 2026
|
@vigneshrajan94, @GCHQDeveloper58, will say you what ai you used? |
Member
|
@vigneshrajan94 thank you for your pull request. In general, we would prefer minimally scoped individual pull requests, rather than pull requests incorporating multiple features/bug fixes. Would you mind splitting the pull request into one for each issue? This makes it easier for us to review and to track changes. |
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.
Summary
Fixes three independent bugs in a single PR.
#2239 — Median returns wrong result for unsorted odd-length inputs
src/core/lib/Arithmetic.mjs—median()The
.sort()call was insideif (even), so odd-length arrays were never sorted before picking the middle element.Median([10, 1, 2])returned1instead of2.Fix: sort unconditionally before branching on even/odd length.
#2241 — Set Difference / Set Intersection preserve duplicates from first input
src/core/operations/SetDifference.mjs,src/core/operations/SetIntersection.mjsBoth operations used a plain
.filter()on arraya. Ifacontained duplicate entries that passed the filter, all copies appeared in the output, violating set semantics.SetDifference(["x","x","y"], ["y"])returned"x,x".Fix: deduplicate
avia[...new Set(a)]before filtering.#2242 — Unescape Unicode Characters rejects code points > 4 hex digits under
U+src/core/operations/UnescapeUnicodeCharacters.mjs—run()The regex quantifier was hardcoded to
{4}for all prefix types. TheU+notation supports 4–6 hex digits (e.g.U+1F600for 😀,U+000041zero-padded).\uand%uremain at{4}per their respective specs.Fix: use
{4,6}when the selected prefix isU+,{4}otherwise.Test plan
npm test— all 2178 tests pass (243 Node API + 1935 operations), zero failuresMedianwith input10,1,2(Comma delimiter) →2Set Differencewith sample 1x,x,y, sample 2y→xSet Intersectionwith sample 1y,y,z, sample 2y→yUnescape Unicode Characters(prefixU+), inputU+1F600→ 😀Unescape Unicode Characters(prefixU+), inputU+000041→AUnescape Unicode Characters(prefix\u), inputA→A(4-digit still works)