From b7aa8b4b8167aa087f830155a90f43286873bdb2 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Sun, 23 Jun 2013 23:16:48 -0500 Subject: [PATCH] issue 96 New styles have a URL of undefined --- background.js | 12 ++++++------ storage.js | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/background.js b/background.js index 84ac06bd..fcd74f07 100644 --- a/background.js +++ b/background.js @@ -198,12 +198,12 @@ function saveStyle(o, callback) { } } else { // create a new record - if (!("updateUrl" in o)) { - o.updateUrl = null; - } - if (!("md5Url" in o)) { - o.md5Url = null; - } + // set optional things to null if they're undefined + ["updateUrl", "md5Url", "url"].filter(function(att) { + return !(att in o); + }).forEach(function(att) { + o[att] = null; + }); t.executeSql('INSERT INTO styles (name, enabled, url, updateUrl, md5Url) VALUES (?, ?, ?, ?, ?);', [o.name, true, o.url, o.updateUrl, o.md5Url]); } diff --git a/storage.js b/storage.js index 3ee901bc..e774482f 100644 --- a/storage.js +++ b/storage.js @@ -11,6 +11,8 @@ function getDatabase(ready, error) { dbV12(stylishDb, error, ready); } else if (stylishDb.version == "1.2") { dbV13(stylishDb, error, ready); + } else if (stylishDb.version == "1.3") { + dbV14(stylishDb, error, ready); } else { ready(stylishDb); } @@ -51,6 +53,12 @@ function dbV13(d, error, done) { }, error, function() { done(d)}); } +function dbV14(d, error, done) { + d.changeVersion(d.version, '1.4', function (t) { + t.executeSql('UPDATE styles SET url = null WHERE url = "undefined";'); + }, error, function() { done(d)}); +} + function enableStyle(id, enabled) { getDatabase(function(db) { db.transaction(function (t) {