Skip to content

Commit 6239d38

Browse files
BBboy01davidchambers
authored andcommitted
fix: update btoa boundary
1 parent 0048721 commit 6239d38

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

base64.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
o2 = data.charCodeAt (i++);
3838
o3 = data.charCodeAt (i++);
3939

40-
if (o1 > 128 || o2 > 128 || o3 > 128) {
40+
if (o1 > 255 || o2 > 255 || o3 > 255) {
4141
throw new InvalidCharacterError ("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
4242
}
4343

test/base64.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ describe ('Base64.js', function() {
2929
assert.strictEqual (btoa ('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4=');
3030
});
3131

32-
it ('cannot encode non-ASCII input', function() {
32+
it ('cannot encode characters beyond U+00FF', function() {
33+
assert.strictEqual (String.fromCharCode (0x2708), '✈');
3334
assert.throws (
3435
function() { btoa ('✈'); },
3536
function(err) {
@@ -83,4 +84,11 @@ describe ('Base64.js', function() {
8384
assert.strictEqual (atob (null), atob ('null'));
8485
});
8586

87+
it ('can encode every character in [U+0000, U+00FF]', function() {
88+
for (var code = 0x0; code <= 0xFF; code += 0x1) {
89+
var char = String.fromCharCode (code);
90+
assert.strictEqual (atob (btoa (char)), char);
91+
}
92+
});
93+
8694
});

0 commit comments

Comments
 (0)