Skip to content

[BUG]: Any media type that isn't JSON and that has UTF-8 charset get cast to text #751

Open
@wolfy1339

Description

@wolfy1339

What happened?

It seems that ever since the very beginning of this project, it has been naively converting every file to text that has charset=utf-8 in it's content type.

The final condition in getResponseData() to return a simple ArrayBuffer is almost never reached because of that

} else if (
mimetype.type.startsWith("text/") ||
mimetype.parameters.charset?.toLowerCase() === "utf-8"
) {
return response.text().catch(() => "");

Reproduction:

import { Octokit } from "octokit";

const octokit = new Octokit({
    auth: "<token>"
});

const response = await octokit.rest.repos.getContent({
    owner: "wolfy1339",
    repo: "test-repository-test",
    path: "training.opus",
    mediaType: {
        format: "raw"
    }
});

console.log(request.data); // Mangled binary data

See also octokit/rest.js#14

Versions

Octokit 4.1.2

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    🆕 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions