Skip to content

Commit

Permalink
Accept Buffer inputs in isBase64()
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Feb 28, 2024
1 parent 7b21565 commit b5a9be3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions create-or-update-files.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
function isBase64(str) {
// Handle buffer inputs
if (Buffer.isBuffer(str)) {
str = str.toString("utf8");
}

var notBase64 = /[^A-Z0-9+\/=]/i;
const isString = (typeof str === 'string' || str instanceof String);

Check failure on line 8 in create-or-update-files.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Replace `(typeof·str·===·'string'·||·str·instanceof·String)` with `typeof·str·===·"string"·||·str·instanceof·String`

Check failure on line 8 in create-or-update-files.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `(typeof·str·===·'string'·||·str·instanceof·String)` with `typeof·str·===·"string"·||·str·instanceof·String`

Check failure on line 8 in create-or-update-files.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `(typeof·str·===·'string'·||·str·instanceof·String)` with `typeof·str·===·"string"·||·str·instanceof·String`

Expand Down
30 changes: 30 additions & 0 deletions create-or-update-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,36 @@ test(`success (base64 encoded body)`, async () => {
await expect(run(body)).resolves.toEqual(mockCommitList);
});

test.only(`success (buffer body provided)`, async () => {
const body = {
...validRequest,
changes: [
{
message: "Your commit message",
files: {
"test.md": Buffer.from(
`# This is a test
I hope it works`

Check failure on line 248 in create-or-update-files.test.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Insert `,`

Check failure on line 248 in create-or-update-files.test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Insert `,`

Check failure on line 248 in create-or-update-files.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `,`
),
"test2.md": {
contents: `Something else`,
},
},
},
],
};

mockGetRef(branch, `sha-${branch}`, true);
mockCreateBlobFileOne();
mockCreateBlobFileTwo();
mockCreateTree(`sha-${branch}`);
mockCommit(`sha-${branch}`);
mockUpdateRef(branch);

await expect(run(body)).resolves.toEqual(mockCommitList);
});

test(`success (committer details)`, async () => {
const committer = {
name: "Ashley Person",
Expand Down

0 comments on commit b5a9be3

Please sign in to comment.