Skip to content

Commit cb5c204

Browse files
committed
buffer: fix atob/btoa no-arg case
1 parent 6b7b0b7 commit cb5c204

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

lib/buffer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,9 @@ function btoa(input) {
12141214
// The implementation here has not been performance optimized in any way and
12151215
// should not be.
12161216
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
1217+
if (arguments.length === 0) {
1218+
throw new ERR_INVALID_ARG_TYPE('input', 'string', input);
1219+
}
12171220
input = `${input}`;
12181221
for (let n = 0; n < input.length; n++) {
12191222
if (input[n].charCodeAt(0) > 0xff)
@@ -1230,6 +1233,9 @@ function atob(input) {
12301233
// The implementation here has not been performance optimized in any way and
12311234
// should not be.
12321235
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
1236+
if (arguments.length === 0) {
1237+
throw new ERR_INVALID_ARG_TYPE('input', 'string', input);
1238+
}
12331239
input = `${input}`;
12341240
for (let n = 0; n < input.length; n++) {
12351241
if (!kBase64Digits.includes(input[n]))

test/parallel/test-btoa-atob-global.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/parallel/test-btoa-atob.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const { strictEqual, throws } = require('assert');
6+
const buffer = require('buffer');
7+
8+
// Exported on the global object
9+
strictEqual(globalThis.atob, buffer.atob);
10+
strictEqual(globalThis.btoa, buffer.btoa);
11+
12+
// Throws type error on no argument passed
13+
throws(() => buffer.atob(), /TypeError/);
14+
throws(() => buffer.btoa(), /TypeError/);

0 commit comments

Comments
 (0)