Skip to content

Commit

Permalink
buffer: switch to using InvalidCharacterError on encoding error
Browse files Browse the repository at this point in the history
* Chrome and Firefox both use `InvalidCharacterError` when the string
  to be decoded is not correctly encoded
* Remove unnecessary atob test
  • Loading branch information
austinkelleher committed Apr 9, 2022
1 parent 08e4c75 commit a85b856
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ function atob(input) {
if (nonAsciiWhitespaceCharCount % 4 === 1) {
throw lazyDOMException(
'The string to be decoded is not correctly encoded.',
'ValidationError');
'InvalidCharacterError');
}

return Buffer.from(input, 'base64').toString('latin1');
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-btoa-atob.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ strictEqual(atob([]), '');
strictEqual(atob({ toString: () => '' }), '');
strictEqual(atob({ [Symbol.toPrimitive]: () => '' }), '');

throws(() => atob(), /ERR_MISSING_ARGS/);
throws(() => atob(Symbol()), /TypeError/);
[undefined, false, () => {}, 0, 1, 0n, 1n, -Infinity, [1], {}].forEach((value) =>
throws(() => atob(value), { constructor: DOMException }));

0 comments on commit a85b856

Please sign in to comment.