Fix unicode-awareness of Base64 encoding implementation in javascript

pull/328/head
Aleksander Machniak 9 years ago
parent 8bbb454524
commit 9ae41d906e

@ -744,16 +744,16 @@ var Base64 = (function () {
* @param {String} input The string to encode in base64. * @param {String} input The string to encode in base64.
*/ */
encode: function (input) { encode: function (input) {
// encode UTF8 as btoa() may fail on some characters
input = utf8_encode(input);
if (typeof(window.btoa) === 'function') { if (typeof(window.btoa) === 'function') {
// it may fail on unicode characters, the fallback can handle them
try { try {
return btoa(input); return btoa(input);
} }
catch (e) {}; catch (e) {};
} }
input = utf8_encode(input);
var chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0, output = '', len = input.length; var chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0, output = '', len = input.length;
while (i < len) { while (i < len) {
@ -785,7 +785,6 @@ var Base64 = (function () {
*/ */
decode: function (input) { decode: function (input) {
if (typeof(window.atob) === 'function') { if (typeof(window.atob) === 'function') {
// it may fail on unicode characters, the fallback can handle them
try { try {
return utf8_decode(atob(input)); return utf8_decode(atob(input));
} }

Loading…
Cancel
Save