From 474690f2a2469dbb8aa853bdf5037571a8a8b490 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Mon, 30 Nov 2009 14:05:20 +0000 Subject: [PATCH] Fixed base64 decoder git-svn-id: http://svg-edit.googlecode.com/svn/trunk@980 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 14 ++++++++------ editor/svgcanvas.js | 33 ++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index bd5dec5a..377e92ac 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -2092,12 +2092,6 @@ function svg_edit_setup() { // var revnums = "svg-editor.js ($Rev$) "; // revnums += svgCanvas.getVersion(); // $('#copyright')[0].setAttribute("title", revnums); - var loc = document.location.href; - if(loc.indexOf('?source=') != -1) { - var pre = '?source=data:image/svg+xml;base64,'; - var src = loc.substring(loc.indexOf(pre) + pre.length); - svgCanvas.setSvgString(Utils.decode64(src)); - } return svgCanvas; }; @@ -2236,6 +2230,14 @@ function setSVGIcons() { // Make smaller svgCanvas.setIconSize('s'); } + + // Load source if given + var loc = document.location.href; + if(loc.indexOf('?source=') != -1) { + var pre = '?source=data:image/svg+xml;base64,'; + var src = loc.substring(loc.indexOf(pre) + pre.length); + svgCanvas.setSvgString(Utils.decode64(src)); + } } }); } diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 7aabb6a3..4ebf400d 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -5996,35 +5996,38 @@ var Utils = { "decode64" : function(input) { if(window.atob) return window.atob(input); - var output = new StringMaker(); - var chr1, chr2, chr3; - var enc1, enc2, enc3, enc4; + var output = ""; + var chr1, chr2, chr3 = ""; + var enc1, enc2, enc3, enc4 = ""; var i = 0; - // remove all characters that are not A-Z, a-z, 0-9, +, /, or = - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + // remove all characters that are not A-Z, a-z, 0-9, +, /, or = + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - while (i < input.length) { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); + do { + enc1 = this._keyStr.indexOf(input.charAt(i++)); + enc2 = this._keyStr.indexOf(input.charAt(i++)); + enc3 = this._keyStr.indexOf(input.charAt(i++)); + enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; - output.append(String.fromCharCode(chr1)); + output = output + String.fromCharCode(chr1); if (enc3 != 64) { - output.append(String.fromCharCode(chr2)); + output = output + String.fromCharCode(chr2); } if (enc4 != 64) { - output.append(String.fromCharCode(chr3)); + output = output + String.fromCharCode(chr3); } - } - return output.toString(); + chr1 = chr2 = chr3 = ""; + enc1 = enc2 = enc3 = enc4 = ""; + + } while (i < input.length); + return unescape(output); }, // based on http://phpjs.org/functions/utf8_encode:577