buffer: fix atob/btoa no-arg case
PR-URL: https://github.com/nodejs/node/pull/41478 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
06625ff0a6
commit
9a8fa71020
@ -96,6 +96,7 @@ const {
|
|||||||
ERR_INVALID_ARG_VALUE,
|
ERR_INVALID_ARG_VALUE,
|
||||||
ERR_INVALID_BUFFER_SIZE,
|
ERR_INVALID_BUFFER_SIZE,
|
||||||
ERR_OUT_OF_RANGE,
|
ERR_OUT_OF_RANGE,
|
||||||
|
ERR_MISSING_ARGS,
|
||||||
ERR_UNKNOWN_ENCODING
|
ERR_UNKNOWN_ENCODING
|
||||||
},
|
},
|
||||||
hideStackFrames
|
hideStackFrames
|
||||||
@ -1218,6 +1219,9 @@ function btoa(input) {
|
|||||||
// The implementation here has not been performance optimized in any way and
|
// The implementation here has not been performance optimized in any way and
|
||||||
// should not be.
|
// should not be.
|
||||||
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
|
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
throw new ERR_MISSING_ARGS('input');
|
||||||
|
}
|
||||||
input = `${input}`;
|
input = `${input}`;
|
||||||
for (let n = 0; n < input.length; n++) {
|
for (let n = 0; n < input.length; n++) {
|
||||||
if (input[n].charCodeAt(0) > 0xff)
|
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
|
// The implementation here has not been performance optimized in any way and
|
||||||
// should not be.
|
// should not be.
|
||||||
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
|
// Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
throw new ERR_MISSING_ARGS('input');
|
||||||
|
}
|
||||||
input = `${input}`;
|
input = `${input}`;
|
||||||
for (let n = 0; n < input.length; n++) {
|
for (let n = 0; n < input.length; n++) {
|
||||||
if (!kBase64Digits.includes(input[n]))
|
if (!kBase64Digits.includes(input[n]))
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
require('../common');
|
|
||||||
|
|
||||||
const { strictEqual } = require('assert');
|
|
||||||
const buffer = require('buffer');
|
|
||||||
|
|
||||||
strictEqual(globalThis.atob, buffer.atob);
|
|
||||||
strictEqual(globalThis.btoa, buffer.btoa);
|
|
14
test/parallel/test-btoa-atob.js
Normal file
14
test/parallel/test-btoa-atob.js
Normal file
@ -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/);
|
Loading…
x
Reference in New Issue
Block a user