diff --git a/src/javascript/utils.js b/src/javascript/utils.js index 52de052d3b..e49191b181 100644 --- a/src/javascript/utils.js +++ b/src/javascript/utils.js @@ -275,13 +275,13 @@ return (myNav.indexOf('msie') !== -1) ? parseInt(myNav.split('msie')[1], 10) : false; }; - OSjs.Utils.urlsafe_b64encode = function(str) { + OSjs.Utils.btoaUrlsafe = function(str) { // Encode return (!str || !str.length) ? '' : btoa(str) .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, ''); }; - OSjs.Utils.urlsafe_b64decode = function(str) { + OSjs.Utils.atobUrlsafe = function(str) { // Decode if ( str && str.length ) { str = (str + '===').slice(0, str.length + (str.length % 4)); return atob(str.replace(/-/g, '+').replace(/_/g, '/')); @@ -289,6 +289,28 @@ return ''; }; + OSjs.Utils.btoaUtf = function(str) { // Encode + var _unescape = window.unescape || function(s) { + function d(x, n) { + return String.fromCharCode(parseInt(n, 16)); + } + return s.replace(/%([0-9A-F]{2})/i, d); + }; + return btoa(_unescape(encodeURIComponent(str))); + }; + + OSjs.Utils.atobUtf = function(str) { // Decode + var _escape = window.escape || function(s) { + function q(c) { + c = c.charCodeAt(); + return '%' + (c<16 ? '0' : '') + c.toString(16).toUpperCase(); + } + return s.replace(/[\x00-),:-?[-^`{-\xFF]/g, q); + }; + + return decodeURIComponent(_escape(atob(str))); + }; + OSjs.Utils.getUserLocale = function() { var loc = (window.navigator.userLanguage || window.navigator.language) || 'en-EN'; var map = { diff --git a/src/javascript/vfs/googledrive.js b/src/javascript/vfs/googledrive.js index e62ceea284..c3dc4cec0e 100644 --- a/src/javascript/vfs/googledrive.js +++ b/src/javascript/vfs/googledrive.js @@ -58,7 +58,7 @@ title: file.filename, mimeType: contentType }; - var base64Data = btoa(unescape(encodeURIComponent(result))); + var base64Data = Utils.btoaUtf(result); var multipartRequestBody = delimiter + 'Content-Type: application/json\r\n\r\n' + diff --git a/src/javascript/vfs/osjs.js b/src/javascript/vfs/osjs.js index cfc10839ef..35d130f0b1 100644 --- a/src/javascript/vfs/osjs.js +++ b/src/javascript/vfs/osjs.js @@ -66,7 +66,7 @@ if ( error ) { return callback(error); } - callback(false, dataSource ? result : decodeURIComponent(escape(atob(result)))); + callback(false, dataSource ? result : Utils.atobUtf(result)); }); }; OSjsStorage.copy = function(src, dest, callback) { diff --git a/src/javascript/vfs/public.js b/src/javascript/vfs/public.js index ad62e91c4d..85a4e001c3 100644 --- a/src/javascript/vfs/public.js +++ b/src/javascript/vfs/public.js @@ -70,7 +70,7 @@ if ( error ) { return callback(error); } - callback(false, dataSource ? result : decodeURIComponent(escape(atob(result)))); + callback(false, dataSource ? result : Utils.atobUtf(result)); }); }; PublicStorage.copy = function(src, dest, callback) {