fix(core): preserve binary output in ProcessOutput.buffer() - #1495
Open
spokodev wants to merge 1 commit into
Open
fix(core): preserve binary output in ProcessOutput.buffer()#1495spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
buffer() built its Buffer from `this.stdall`, which is a UTF-8 decoded string, so any non-UTF-8 byte in the command output was already replaced with U+FFFD and the returned bytes were corrupted — even though the raw chunks are still retained in the store. blob() and text(<encoding>) both delegate to buffer(), so they were affected too: await $`cat image.png`.buffer() // mangled bytes Rebuild the Buffer from the lossless store chunks instead.
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.
Problem
ProcessOutput.buffer()builds itsBufferfromthis.stdall:But
stdallis a getter that UTF-8 decodes the stored chunks(
bufArrJoin→TextDecoder('utf-8').decode). Any byte that isn't validUTF-8 has already been replaced with
U+FFFDby the timebuffer()runs, sothe bytes it returns are corrupted — even though the original, lossless chunks
are still sitting in
this._dto.store.stdall.blob()andtext(<encoding>)both delegate tobuffer(), so they areaffected too. These are the documented APIs for getting bytes out of a command:
Reproduction
Fix
Reconstruct the
Bufferfrom the raw store chunks (which are the originalstring | Bufferpieces) instead of the decoded string:This also fixes
blob()andtext('hex' | 'base64' | 'latin1' | …), which gothrough
buffer(). The plain-text path (toString()/text()) is unchanged.Test
Added a
buffer()case intest/core.test.jsasserting that non-UTF-8 bytessurvive
buffer()/text('hex'). Fails onmain, passes with the fix; theexisting
buffer()/text()/blob()string tests still pass.