fix: use StringDecoder for stdout/stderr to prevent UTF-8 corruption#15387
Open
mfleming wants to merge 1 commit intoanomalyco:devfrom
Open
fix: use StringDecoder for stdout/stderr to prevent UTF-8 corruption#15387mfleming wants to merge 1 commit intoanomalyco:devfrom
mfleming wants to merge 1 commit intoanomalyco:devfrom
Conversation
Buffer.toString() on raw stdout chunks can split multi-byte UTF-8 characters (e.g. emdash U+2014 = 3 bytes) across data events, producing replacement characters. Use StringDecoder which buffers incomplete sequences across chunks.
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 for this PR
Fixes #15385
Type of change
What does this PR do?
src/tool/bash.tsandsrc/session/prompt.tsassemble child process stdout withoutput += chunk.toString(). Node delivers stdout as raw byte Buffers, and a multi-byte UTF-8 character (e.g. emdash = 3 bytes) can be split across twodataevents. Eachchunk.toString()decodes its fragment independently, producing replacement characters.Fix: use
StringDecoderfromstring_decoderwhich buffers incomplete UTF-8 sequences across chunks.How did you verify your code works?
Test in
test/tool/utf8-stdout.test.tsspawns a child process that deliberately splits an emdash across two stdout writes. Verifies thatchunk.toString()produces corruption andStringDecoder.write()doesn't.Checklist