X Tutup
The Wayback Machine - https://web.archive.org/web/20220321200656/https://github.com/nodejs/node/commit/6064b1df5d
Skip to content
Permalink
Browse files
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>
  • Loading branch information
benjamingr authored and ruyadorno committed Feb 8, 2022
1 parent e11a079 commit 6064b1df5d5bda44d511e5f50da7ee59acb4f079
Showing with 21 additions and 9 deletions.
  1. +7 −0 lib/buffer.js
  2. +0 −9 test/parallel/test-btoa-atob-global.js
  3. +14 −0 test/parallel/test-btoa-atob.js
@@ -96,6 +96,7 @@ const {
ERR_INVALID_ARG_VALUE,
ERR_INVALID_BUFFER_SIZE,
ERR_OUT_OF_RANGE,
ERR_MISSING_ARGS,
ERR_UNKNOWN_ENCODING
},
hideStackFrames
@@ -1218,6 +1219,9 @@ function btoa(input) {
// The implementation here has not been performance optimized in any way and
// should not be.
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('input');
}
input = `${input}`;
for (let n = 0; n < input.length; n++) {
if (input[n].charCodeAt(0) > 0xff)
@@ -1234,6 +1238,9 @@ function atob(input) {
// The implementation here has not been performance optimized in any way and
// should not be.
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('input');
}
input = `${input}`;
for (let n = 0; n < input.length; n++) {
if (!kBase64Digits.includes(input[n]))

This file was deleted.

@@ -0,0 +1,14 @@
'use strict';

require('../common');

const { strictEqual, throws } = require('assert');
const buffer = require('buffer');

// Exported on the global object
strictEqual(globalThis.atob, buffer.atob);
strictEqual(globalThis.btoa, buffer.btoa);

// Throws type error on no argument passed
throws(() => buffer.atob(), /TypeError/);
throws(() => buffer.btoa(), /TypeError/);

0 comments on commit 6064b1d

Please sign in to comment.
X Tutup