This repository was archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Issues with Base64 encoded values in 1.2.6 #69
Copy link
Copy link
Open
Description
Hello,
I'm playing around with 1.2.6 and porting previous player from 1.2.1 to this new release and I have noticed that these lines of code in 1.2.1 are false and in 1.2.6 are true (i.e. the btoa and atob are undefined)
if (undefined === btoa) {
var btoa = BASE64.encode;
}
if (undefined === atob) {
var atob = BASE64.decode;
}
This results in btoa becoming BASE64.encode and this method creates wrong Base64 values. To test, take this Uin8Array
var arr = new Uint8Array([34, 108, 58, 142, 214, 53, 79, 38, 147, 249, 93, 97, 85, 57, 72, 44]);
Run it through this function
function bufferToBase64(buf) {
var binstr = Array.prototype.map.call(buf, function (ch) {
return String.fromCharCode(ch);
}).join('');
var x = BASE64.encode(binstr);
var z = window.btoa(binstr);
}
And compare X and Z.
What I currently did to fix the issue is changed the following code
if (undefined === this.btoa) {
var btoa = BASE64.encode;
}
if (undefined === this.atob) {
var atob = BASE64.decode;
}
to this
var btoa = this.btoa === undefined ? BASE64.encode : this.btoa;
var atob = this.atob === undefined ? BASE64.decode : this.atob;
Please, correct me if I'm wrong. Thank you.
Metadata
Metadata
Assignees
Labels
No labels