Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6064b1d

Browse filesBrowse files
benjamingrruyadorno
authored andcommitted
buffer: fix atob/btoa no-arg case
PR-URL: #41478 Fixes: #41450 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent e11a079 commit 6064b1d
Copy full SHA for 6064b1d

File tree

Expand file treeCollapse file tree

3 files changed

+21
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-9
lines changed
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const {
9696
ERR_INVALID_ARG_VALUE,
9797
ERR_INVALID_BUFFER_SIZE,
9898
ERR_OUT_OF_RANGE,
99+
ERR_MISSING_ARGS,
99100
ERR_UNKNOWN_ENCODING
100101
},
101102
hideStackFrames
@@ -1218,6 +1219,9 @@ function btoa(input) {
12181219
// The implementation here has not been performance optimized in any way and
12191220
// should not be.
12201221
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
1222+
if (arguments.length === 0) {
1223+
throw new ERR_MISSING_ARGS('input');
1224+
}
12211225
input = `${input}`;
12221226
for (let n = 0; n < input.length; n++) {
12231227
if (input[n].charCodeAt(0) > 0xff)
@@ -1234,6 +1238,9 @@ function atob(input) {
12341238
// The implementation here has not been performance optimized in any way and
12351239
// should not be.
12361240
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
1241+
if (arguments.length === 0) {
1242+
throw new ERR_MISSING_ARGS('input');
1243+
}
12371244
input = `${input}`;
12381245
for (let n = 0; n < input.length; n++) {
12391246
if (!kBase64Digits.includes(input[n]))
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-btoa-atob-global.js
-9Lines changed: 0 additions & 9 deletions
This file was deleted.
Collapse file

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

Copy file name to clipboard
+14Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.