From 8737d6e29d4e456865014dc9a8402553da0591d9 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Fri, 16 Mar 2012 19:07:19 -0600 Subject: [PATCH] defend against garbage in localStorage --- resources/static/shared/storage.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/static/shared/storage.js b/resources/static/shared/storage.js index b25b65af0..a7bad71bc 100644 --- a/resources/static/shared/storage.js +++ b/resources/static/shared/storage.js @@ -330,7 +330,13 @@ BrowserID.Storage = (function() { // this map helps us determine whether a specific email address belongs // to a user who has already confirmed their ownership of a computer. function updateEmailToUserIDMapping(userid, emails) { - var allInfo = JSON.parse(storage.emailToUserID || "{}"); + var allInfo; + try { + allInfo = JSON.parse(storage.emailToUserID); + if (typeof allInfo != 'object' || allInfo === null) throw "bogus"; + } catch(e) { + allInfo = {}; + } _.each(emails, function(email) { allInfo[email] = userid; }); -- GitLab