Skip to content

fix: don't decode application/octet-stream as text when charset is utf-8 - #823

Merged
wolfy1339 merged 1 commit into
octokit:mainfrom
CedricConday:fix/octet-stream-charset
Aug 1, 2026
Merged

wolfy1339 merged 1 commit into
octokit:mainfrom
CedricConday:fix/octet-stream-charset

Conversation

@CedricConday

Copy link
Copy Markdown
Contributor

Fixes the binary-mangling case of #751.

Problem

getResponseData() decodes any response carrying charset=utf-8 as text — including application/octet-stream, the canonical "arbitrary binary" media type (RFC 2046). A raw binary file (the reproduction in #751 fetches one with mediaType: { format: "raw" }) is run through response.text() and comes back as mangled string data instead of an ArrayBuffer.

Fix

Exclude application/octet-stream from the charset-based text branch so it falls through to arrayBuffer().

Deliberately narrow and zero-regression: charset alone can't tell text from binary (GitHub sends charset=utf-8 on application/vnd.github.v3.raw text and on binary blobs), but application/octet-stream unambiguously means opaque bytes and must never be decoded as text. Genuinely textual responses — text/* and other charset=utf-8 types like application/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-8 is returned as an ArrayBuffer and round-trips through gunzip intact. Full suite green (100 passed), tsc + prettier clean.

Broader binary types with a misleading charset could be handled with a fuller text/binary heuristic, but that's a larger design call — this closes the canonical, unambiguous case.

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
@octokit

octokit Bot commented Jul 9, 2026

Copy link
Copy Markdown

👋 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 Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339
wolfy1339 merged commit facf3cb into octokit:main Aug 1, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 Triage to ✅ Done in 🧰 Octokit Active Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 10.0.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants