From 47cf9b6980db61d8b0808fdea3e52c76b057ee72 Mon Sep 17 00:00:00 2001 From: Chris Wiegand Date: Tue, 3 Jun 2014 21:55:16 -0600 Subject: [PATCH] fix JSON.parse(null) if window.localStorage.config is null then JSON.parse returns an error about "u" not being valid (the word "undefined" is not valid JSON apparently :). So I test for null-ness first. --- src/config/localStorage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/localStorage.js b/src/config/localStorage.js index fe59fdf3..4eafa45a 100644 --- a/src/config/localStorage.js +++ b/src/config/localStorage.js @@ -17,7 +17,8 @@ function LocalStorage() { * if config is null the default config will be used */ LocalStorage.prototype.read = function () { - var cf = JSON.parse(window.localStorage.getItem("config")); + var raw = window.localStorage.getItem("config"); + var cf = (raw === null ? null : JSON.parse(raw)); if (cf === null) { this.config = this.default_config; this.write();