Skip to content

Commit 33b7ddf

Browse files
authored
Merge pull request #1454 from zloirock/uint8array-detection
2 parents 2fbb08f + 3cdc078 commit 33b7ddf

File tree

7 files changed

+33
-4
lines changed

7 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
## Changelog
22
##### Unreleased
33
- Added missing dependencies to some entries of static `Iterator` methods
4+
- Added detection of Webkit bug: `Uint8Array` fromBase64 / setFromBase64 does not throw an error on incorrect length of base64 string
45
- Compat data improvements:
56
- [`Uint8Array` to / from base64 and hex proposal](https://github.com/tc39/proposal-arraybuffer-base64) features marked as [supported from V8 ~ Chromium 140](https://issues.chromium.org/issues/42204568#comment37)
67
- `%TypedArray%.prototype.with` marked as fixed in Safari 26.0
78
- Updated Electron 38 compat data mapping
89
- Added Opera Android 91 compat data mapping
10+
- `Uint8Array` fromBase64 / setFromBase64 marked as unsupported in Safari and Bun because of a bug: it does not throw an error on incorrect length of base64 string
911

1012
##### [3.44.0 - 2025.07.07](https://github.com/zloirock/core-js/releases/tag/v3.44.0)
1113
- Changes [v3.43.0...v3.44.0](https://github.com/zloirock/core-js/compare/v3.43.0...v3.44.0) (87 commits)

packages/core-js-compat/src/data.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,10 +2809,12 @@ export const data = {
28092809
// TODO: Remove from `core-js@4`
28102810
'esnext.typed-array.with': null,
28112811
'esnext.uint8-array.from-base64': {
2812-
bun: '1.1.22',
2812+
// Because of a bug: it doesn't throw an error on incorrect length of base64 string
2813+
// bun: '1.1.22',
28132814
chrome: '140',
28142815
firefox: '133',
2815-
safari: '18.2',
2816+
// Because of a bug: it doesn't throw an error on incorrect length of base64 string
2817+
// safari: '18.2',
28162818
},
28172819
'esnext.uint8-array.from-hex': {
28182820
bun: '1.1.22',
@@ -2821,10 +2823,12 @@ export const data = {
28212823
safari: '18.2',
28222824
},
28232825
'esnext.uint8-array.set-from-base64': {
2824-
bun: '1.1.22',
2826+
// Because of a bug: it doesn't throw an error on incorrect length of base64 string
2827+
// bun: '1.1.22',
28252828
chrome: '140',
28262829
firefox: '133',
2827-
safari: '18.2',
2830+
// Because of a bug: it doesn't throw an error on incorrect length of base64 string
2831+
// safari: '18.2',
28282832
},
28292833
'esnext.uint8-array.set-from-hex': {
28302834
bun: '1.1.22',

packages/core-js/modules/esnext.uint8-array.from-base64.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ var $fromBase64 = require('../internals/uint8-from-base64');
77
var Uint8Array = globalThis.Uint8Array;
88

99
var INCORRECT_BEHAVIOR_OR_DOESNT_EXISTS = !Uint8Array || !Uint8Array.fromBase64 || !function () {
10+
// Webkit not throw an error on odd length string
11+
try {
12+
Uint8Array.fromBase64('a');
13+
return;
14+
} catch (error) { /* empty */ }
1015
try {
1116
Uint8Array.fromBase64('', null);
1217
} catch (error) {

packages/core-js/modules/esnext.uint8-array.set-from-base64.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ var INCORRECT_BEHAVIOR_OR_DOESNT_EXISTS = !Uint8Array || !Uint8Array.prototype.s
1212
target.setFromBase64('', null);
1313
return;
1414
} catch (error) { /* empty */ }
15+
// Webkit not throw an error on odd length string
16+
try {
17+
target.setFromBase64('a');
18+
return;
19+
} catch (error) { /* empty */ }
1520
try {
1621
target.setFromBase64('MjYyZg===');
1722
} catch (error) {

tests/compat/tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,10 @@ GLOBAL.tests = {
20172017
return Int8Array.prototype.uniqueBy;
20182018
},
20192019
'esnext.uint8-array.from-base64': function () {
2020+
try {
2021+
Uint8Array.fromBase64('a');
2022+
return;
2023+
} catch (error) { /* empty */ }
20202024
if (!Uint8Array.fromBase64) return false;
20212025
try {
20222026
Uint8Array.fromBase64('', null);
@@ -2033,6 +2037,10 @@ GLOBAL.tests = {
20332037
target.setFromBase64('', null);
20342038
return false;
20352039
} catch (error) { /* empty */ }
2040+
try {
2041+
target.setFromBase64('a');
2042+
return;
2043+
} catch (error) { /* empty */ }
20362044
try {
20372045
target.setFromBase64('MjYyZg===');
20382046
} catch (error) {

tests/unit-global/esnext.uint8-array.from-base64.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,6 @@ if (DESCRIPTORS) QUnit.test('Uint8Array.fromBase64', assert => {
150150
assert.same(arr.buffer.byteLength, 1);
151151
assert.arrayEqual(arr, [102], `ascii whitespace: ${ name }`);
152152
});
153+
154+
assert.throws(() => Uint8Array.fromBase64('a'), SyntaxError, 'throws error on incorrect length of base64 string');
153155
});

tests/unit-global/esnext.uint8-array.set-from-base64.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,7 @@ if (DESCRIPTORS) QUnit.test('Uint8Array.prototype.setFromBase64', assert => {
286286
target = new Uint8Array([255, 255, 255, 255, 255]);
287287
assert.throws(() => target.setFromBase64('MjYyZg==='), SyntaxError, 'extra characters after padding');
288288
assert.arrayEqual(target, [50, 54, 50, 255, 255], 'decoding from MjYyZg=== should not write the last chunk because it has extra padding');
289+
290+
target = new Uint8Array([255, 255, 255, 255, 255]);
291+
assert.throws(() => target.setFromBase64('a'), SyntaxError, 'throws error on incorrect length of base64 string');
289292
});

0 commit comments

Comments
 (0)