From 9ae41d906e5c68da2e6dca295f9404b177fbc0d1 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 22 Feb 2016 12:35:14 -0500
Subject: [PATCH] Fix unicode-awareness of Base64 encoding implementation in javascript

---
 program/js/common.js |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/program/js/common.js b/program/js/common.js
index 329ffb5..158f8cc 100644
--- a/program/js/common.js
+++ b/program/js/common.js
@@ -744,15 +744,15 @@
      * @param {String} input The string to encode in base64.
      */
     encode: function (input) {
+      // encode UTF8 as btoa() may fail on some characters
+      input = utf8_encode(input);
+
       if (typeof(window.btoa) === 'function') {
-        // it may fail on unicode characters, the fallback can handle them
         try {
           return btoa(input);
         }
         catch (e) {};
       }
-
-      input = utf8_encode(input);
 
       var chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0, output = '', len = input.length;
 
@@ -785,7 +785,6 @@
      */
     decode: function (input) {
       if (typeof(window.atob) === 'function') {
-        // it may fail on unicode characters, the fallback can handle them
         try {
           return utf8_decode(atob(input));
         }

--
Gitblit v1.9.1