Skip to content

Keep a surrogate pair at the cap's head/tail split when the output fits - #127

Merged
HalRiveria merged 3 commits into
mainfrom
fix/surrogate-at-cap-split
Dec 3, 2026
Merged

HalRiveria merged 3 commits into
mainfrom
fix/surrogate-at-cap-split

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Depends on #126, merge after it.

What was wrong

With -MaxOutputChars, the kit keeps a head (the first half of the cap) and a tail (the rest). When the head would end on the first half of a surrogate pair, it turns that half away, but the tail kept its own size. So output exactly as long as the cap, with a pair where the head ends, lost that pair: a😀b under a cap of 4 came back as ab, with 2 counted as dropped, and a lone emoji under a cap of 2 came back empty.

What changed

When the head turns away a pair's first half, the tail takes its slot (set before the tail is allocated). Output that fits the cap is kept whole, and the total kept still never exceeds the cap. A C# change in PkStreamReadTask, under the type version 4.3 already bumped.

How it was tested

Harness section BE: a real program's output (cmd /u /c echo ab😀c, 7 characters) under a cap of 7 comes back whole; PkStreamReadTask keeps an emoji under a cap of 2, a😀b under 4 and ab😀cd under 6 whole. The existing surrogate test now uses a cap of 7, so the head's end and the tail's start both land inside pairs.

Before the fix (main's kit with the new harness), 5.1 and 7 alike:

  [FAIL] output exactly at the cap, with a surrogate pair at the head's end, comes back whole ('abc\r\n', dropped 2)
  [FAIL] the same for an emoji under a cap of 2, a<emoji>b under 4 and ab<emoji>cd under 6 (<emoji> cap 2: kept '', dropped 2; a<emoji>b cap 4: kept 'ab', dropped 2; ab<emoji>cd cap 6: kept 'abcd', dropped 2)
2 FAILED, 16 passed

After: the full harness passes on Windows PowerShell 5.1 and PowerShell 7 (799 assertions each), and Build/Update-ParallelKitCSharp.ps1 -Compile builds the C# with no warnings under csc (C# 5) and dotnet (LangVersion 5).

…fer only in case

A case-sensitive [hashtable]::new() job with 'canceltoken' got the kit's own token in its place, since the check used the job's own comparer and the worker's copy is case-insensitive. Two keys differing only in case collapsed into one, the later silently winning; such a job is now refused, up front for -JobParams and as it arrives for -NextJobProvider.
When -MaxOutputChars' head would end on the first half of a surrogate pair, it turned that half away but the tail kept its own size, so output exactly as long as the cap lost the pair. The tail now takes the slot the head turns away.
@HalRiveria
HalRiveria merged commit 74131b2 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/surrogate-at-cap-split branch December 3, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants