Skip to content

Commit

Permalink
fix: update btoa boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
BBboy01 authored and davidchambers committed Sep 18, 2023
1 parent 0048721 commit 6239d38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
o2 = data.charCodeAt (i++);
o3 = data.charCodeAt (i++);

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

Expand Down
10 changes: 9 additions & 1 deletion test/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe ('Base64.js', function() {
assert.strictEqual (btoa ('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4=');
});

it ('cannot encode non-ASCII input', function() {
it ('cannot encode characters beyond U+00FF', function() {
assert.strictEqual (String.fromCharCode (0x2708), '✈');
assert.throws (
function() { btoa ('✈'); },
function(err) {
Expand Down Expand Up @@ -83,4 +84,11 @@ describe ('Base64.js', function() {
assert.strictEqual (atob (null), atob ('null'));
});

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

});

0 comments on commit 6239d38

Please sign in to comment.