Repository navigation
fix: don't decode application/octet-stream as text when charset is utf-8 - #823
Merged
Merged
Conversation
getResponseData() treats any response carrying charset=utf-8 as text, even
application/octet-stream — the canonical "arbitrary binary" media type
(RFC 2046). Binary content (e.g. a raw binary file fetched with
mediaType: { format: "raw" }) is therefore run through response.text() and
mangled instead of being returned as an ArrayBuffer.
Exclude application/octet-stream from the charset-based text branch so it
falls through to arrayBuffer(). Genuinely textual responses (text/* and
other charset=utf-8 types such as application/vnd.github.v3.raw) are
unaffected.
Refs #751
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
wolfy1339
approved these changes
Aug 1, 2026
|
🎉 This PR is included in version 10.0.12 🎉 The release is available on: Your semantic-release bot 📦🚀 |
1 task done
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.
Fixes the binary-mangling case of #751.
Problem
getResponseData()decodes any response carryingcharset=utf-8as text — includingapplication/octet-stream, the canonical "arbitrary binary" media type (RFC 2046). A raw binary file (the reproduction in #751 fetches one withmediaType: { format: "raw" }) is run throughresponse.text()and comes back as mangled string data instead of anArrayBuffer.Fix
Exclude
application/octet-streamfrom the charset-based text branch so it falls through toarrayBuffer().Deliberately narrow and zero-regression:
charsetalone can't tell text from binary (GitHub sendscharset=utf-8onapplication/vnd.github.v3.rawtext and on binary blobs), butapplication/octet-streamunambiguously means opaque bytes and must never be decoded as text. Genuinely textual responses —text/*and othercharset=utf-8types likeapplication/vnd.github.v3.raw— are unaffected (the existing "non-JSON response" test still passes).Test
Added a regression test: a binary payload served as
application/octet-stream; charset=utf-8is returned as anArrayBufferand round-trips throughgunzipintact. Full suite green (100 passed),tsc+ prettier clean.Broader binary types with a misleading
charsetcould be handled with a fuller text/binary heuristic, but that's a larger design call — this closes the canonical, unambiguous case.