Skip to content

Commit c8112ea

Browse files
committed
Accept Buffer inputs in isBase64()
1 parent 7b21565 commit c8112ea

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

create-or-update-files.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
function isBase64(str) {
2+
// Handle buffer inputs
3+
if (Buffer.isBuffer(str)) {
4+
str = str.toString("utf8");
5+
}
6+
27
var notBase64 = /[^A-Z0-9+\/=]/i;
38
const isString = (typeof str === 'string' || str instanceof String);
49

create-or-update-files.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,36 @@ test(`success (base64 encoded body)`, async () => {
235235
await expect(run(body)).resolves.toEqual(mockCommitList);
236236
});
237237

238+
test(`success (buffer body provided)`, async () => {
239+
const body = {
240+
...validRequest,
241+
changes: [
242+
{
243+
message: "Your commit message",
244+
files: {
245+
"test.md": Buffer.from(
246+
`# This is a test
247+
248+
I hope it works`
249+
),
250+
"test2.md": {
251+
contents: `Something else`,
252+
},
253+
},
254+
},
255+
],
256+
};
257+
258+
mockGetRef(branch, `sha-${branch}`, true);
259+
mockCreateBlobFileOne();
260+
mockCreateBlobFileTwo();
261+
mockCreateTree(`sha-${branch}`);
262+
mockCommit(`sha-${branch}`);
263+
mockUpdateRef(branch);
264+
265+
await expect(run(body)).resolves.toEqual(mockCommitList);
266+
});
267+
238268
test(`success (committer details)`, async () => {
239269
const committer = {
240270
name: "Ashley Person",

0 commit comments

Comments
 (0)