Skip to content

Commit

Permalink
one more atob bug on NodeJS
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 8, 2022
1 parent d1687e7 commit 1f6985c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@
- Moved to Stage 3, [March TC39 meeting](https://github.com/babel/proposals/issues/81#issuecomment-1083449843)
- `Array.prototype.toSpliced` throws a `TypeError` instead of `RangeError` if the result length is more than `MAX_SAFE_INTEGER`, [proposal-change-array-by-copy/70](https://github.com/tc39/proposal-change-array-by-copy/pull/70)
- Added some more `atob` / `btoa` fixes:
- NodeJS <17.9 `atob` does not ignore spaces, [node/42530](https://github.com/nodejs/node/issues/42530)
- Actual NodeJS `atob` does not validate encoding, [node/42646](https://github.com/nodejs/node/issues/42646)
- FF26- implementation does not properly convert argument to string
- IE / Edge <16 implementation have wrong arity
- Significant internal refactoring and splitting of modules (but without exposing to public API since it will be a breaking change - it will be exposed in the next major version)
Expand All @@ -13,7 +15,6 @@
- Tooling:
- Stabilized proposals are filtered out from the `core-js-compat` -> `core-js-builder` -> `core-js-bundle` output. That mean that if the output contains, for example, `es.object.has-own`, the legacy reference to it, `esnext.object.has-own`, will not be added.
- Compat data:
- `atob` marked as not supported in the actual NodeJS (again) because of [the bug](https://github.com/nodejs/node/issues/42530)
- `.stack` property on `DOMException` marked as supported from Deno [1.15](https://github.com/denoland/deno/releases/tag/v1.15.0)
- Added Deno 1.21 compat data mapping
- Added Electron 19.0 and updated 18.0 compat data mapping
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js-compat/src/data.mjs
Expand Up @@ -1915,7 +1915,8 @@ export const data = {
firefox: '27',
// https://github.com/nodejs/node/issues/41450
// https://github.com/nodejs/node/issues/42530
// node: '17.5', '16.0',
// https://github.com/nodejs/node/issues/42646
// node: '17.9', 17.5', '16.0',
opera: '10.5',
safari: '10.1',
},
Expand Down
12 changes: 8 additions & 4 deletions packages/core-js/modules/web.atob.js
Expand Up @@ -18,18 +18,22 @@ var replace = uncurryThis(''.replace);
var exec = uncurryThis(disallowed.exec);

var NO_SPACES_IGNORE = fails(function () {
return atob(' ') !== '';
return $atob(' ') !== '';
});

var NO_ARG_RECEIVING_CHECK = !NO_SPACES_IGNORE && !fails(function () {
var NO_ENCODING_CHECK = !fails(function () {
$atob('a');
});

var NO_ARG_RECEIVING_CHECK = !NO_SPACES_IGNORE && !NO_ENCODING_CHECK && !fails(function () {
$atob();
});

var WRONG_ARITY = !NO_SPACES_IGNORE && $atob.length !== 1;
var WRONG_ARITY = !NO_SPACES_IGNORE && !NO_ENCODING_CHECK && $atob.length !== 1;

// `atob` method
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
$({ global: true, enumerable: true, forced: NO_SPACES_IGNORE || NO_ARG_RECEIVING_CHECK || WRONG_ARITY }, {
$({ global: true, enumerable: true, forced: NO_SPACES_IGNORE || NO_ENCODING_CHECK || NO_ARG_RECEIVING_CHECK || WRONG_ARITY }, {
atob: function atob(data) {
validateArgumentsLength(arguments.length, 1);
if (NO_ARG_RECEIVING_CHECK || WRONG_ARITY) return $atob(data);
Expand Down
8 changes: 6 additions & 2 deletions tests/compat/tests.js
Expand Up @@ -1696,8 +1696,12 @@ GLOBAL.tests = {
'web.atob': function () {
try {
atob();
} catch (error) {
return atob(' ') === '';
} catch (error1) {
try {
atob('a');
} catch (error2) {
return atob(' ') === '';
}
}
},
'web.btoa': function () {
Expand Down

0 comments on commit 1f6985c

Please sign in to comment.