diff --git a/editor/extensions/ext-storage.js b/editor/extensions/ext-storage.js index 709933cb..3072dd18 100644 --- a/editor/extensions/ext-storage.js +++ b/editor/extensions/ext-storage.js @@ -67,22 +67,30 @@ svgEditor.addExtension('storage', function() { } } } - function removeStoragePrefCookie () { - document.cookie = 'store=; expires=Thu, 01 Jan 1970 00:00:00 GMT'; + + function expireCookie (cookie) { + document.cookie = encodeURIComponent(cookie) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT'; } - function emptyLocalStorage() { + + function removeStoragePrefCookie () { + expireCookie('store'); + } + + function emptyStorage() { setSVGContentStorage(''); - var name; - if ('localStorage' in window) { - for (name in svgEditor.curPrefs) { - if (svgEditor.curPrefs.hasOwnProperty(name)) { + var name, hasStorage = 'localStorage' in window; + for (name in svgEditor.curPrefs) { + if (svgEditor.curPrefs.hasOwnProperty(name)) { + name = 'svg-edit-' + name; + if (hasStorage) { window.localStorage.removeItem(name); } + expireCookie(name); } } } -// emptyLocalStorage(); +// emptyStorage(); /** * Listen for unloading: If and only if opted in by the user, set the content @@ -124,7 +132,7 @@ svgEditor.addExtension('storage', function() { } else { val = encodeURIComponent(val); - document.cookie = key + '=' + val + '; expires=Fri, 31 Dec 9999 23:59:59 GMT'; + document.cookie = encodeURIComponent(key) + '=' + val + '; expires=Fri, 31 Dec 9999 23:59:59 GMT'; } } } @@ -223,7 +231,7 @@ svgEditor.addExtension('storage', function() { // doesn't even want to remember their not wanting // storage, so we don't set the cookie or continue on with // setting storage on beforeunload - document.cookie = 'store=' + pref + '; expires=Fri, 31 Dec 9999 23:59:59 GMT'; // 'prefsAndContent' | 'prefsOnly' + document.cookie = 'store=' + encodeURIComponent(pref) + '; expires=Fri, 31 Dec 9999 23:59:59 GMT'; // 'prefsAndContent' | 'prefsOnly' // If the URL was configured to always insist on a prompt, if // the user does indicate a wish to store their info, we // don't want ask them again upon page refresh so move @@ -235,8 +243,10 @@ svgEditor.addExtension('storage', function() { } else { // The user does not wish storage (or cancelled, which we treat equivalently) removeStoragePrefCookie(); - if (emptyStorageOnDecline) { - emptyLocalStorage(); + if (pref && // If the user explicitly expresses wish for no storage + emptyStorageOnDecline + ) { + emptyStorage(); } if (pref && checked) { // Open a URL which won't set storage and won't prompt user about storage diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 2c6be1ba..c034eb30 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -40,6 +40,7 @@ TO-DOS editor.storagePromptClosed = false; // For use with ext-storage.js var svgCanvas, urldata, + Utils = svgedit.utilities, isReady = false, callbacks = [], customHandlers = {}, @@ -272,7 +273,7 @@ TO-DOS defaultPrefs[key] = widget.preferenceForKey(storeKey); } else { - var result = document.cookie.match(new RegExp('(?:^|;\\s*)' + storeKey + '=([^;]+)')); + var result = document.cookie.match(new RegExp('(?:^|;\\s*)' + Utils.preg_quote(encodeURIComponent(storeKey)) + '=([^;]+)')); defaultPrefs[key] = result ? decodeURIComponent(result[1]) : ''; } } @@ -771,7 +772,6 @@ TO-DOS modKey = (svgedit.browser.isMac() ? 'meta+' : 'ctrl+'), // ⌘ path = svgCanvas.pathActions, undoMgr = svgCanvas.undoMgr, - Utils = svgedit.utilities, defaultImageURL = curConfig.imgPath + 'logo.png', workarea = $('#workarea'), canv_menu = $('#cmenu_canvas'), @@ -5099,7 +5099,7 @@ TO-DOS editor.ready(function() { var pre = 'data:image/svg+xml;base64,'; var src = str.substring(pre.length); - loadSvgString(svgedit.utilities.decode64(src)); + loadSvgString(Utils.decode64(src)); }); }; diff --git a/editor/svgutils.js b/editor/svgutils.js index 48876a35..1aea110e 100644 --- a/editor/svgutils.js +++ b/editor/svgutils.js @@ -716,4 +716,9 @@ svgedit.utilities.snapToGrid = function(value) { return value; }; +svgedit.utilities.preg_quote = function (str, delimiter) { + // From: http://phpjs.org/functions + return String(str).replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&'); +}; + }());