diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 1251da90c3..2f20955afd 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -580,19 +580,6 @@ Zotero.Tags = new function() { } var tagColors = Zotero.SyncedSettings.get(libraryID, 'tagColors'); - - // Sanitize -- shouldn't be necessary, but just in case a bad value makes it into the setting - if (!Array.isArray(tagColors)) { - tagColors = []; - } - tagColors = tagColors.filter(color => { - if (typeof color != 'object' || typeof color.name != 'string' || typeof color.color != 'string') { - Zotero.logError("Skipping invalid colored tag: " + JSON.stringify(color)); - return false; - } - return true; - }); - _libraryColors[libraryID] = tagColors; _libraryColorsByName[libraryID] = new Map; @@ -619,9 +606,10 @@ Zotero.Tags = new function() { } this.getColors(libraryID); - var tagColors = _libraryColors[libraryID]; + name = name.trim(); + // Unset if (!color) { // Trying to clear color on tag that doesn't have one diff --git a/chrome/content/zotero/xpcom/syncedSettings.js b/chrome/content/zotero/xpcom/syncedSettings.js index 62edde3ed4..886330c4d9 100644 --- a/chrome/content/zotero/xpcom/syncedSettings.js +++ b/chrome/content/zotero/xpcom/syncedSettings.js @@ -70,7 +70,7 @@ Zotero.SyncedSettings = (function () { }) }, - loadAll: Zotero.Promise.coroutine(function* (libraryID) { + loadAll: async function (libraryID) { Zotero.debug("Loading synced settings for library " + libraryID); if (!_cache[libraryID]) { @@ -81,7 +81,7 @@ Zotero.SyncedSettings = (function () { var sql = "SELECT setting, value, synced, version FROM syncedSettings " + "WHERE libraryID=?"; - yield Zotero.DB.queryAsync( + await Zotero.DB.queryAsync( sql, libraryID, { @@ -106,8 +106,41 @@ Zotero.SyncedSettings = (function () { } ); - // TODO: Delete invalid settings - }), + // + // Delete invalid settings + // + if (_cache[libraryID].tagColors) { + // Sanitize colored tags -- shouldn't be necessary, but just in case a bad value makes it + // into the setting + let fixed = false; + let tagColors = _cache[libraryID].tagColors.value; + // Not an array + if (!Array.isArray(tagColors)) { + tagColors = []; + fixed = true; + } + // Invalid tag + tagColors = tagColors.filter((color) => { + if (typeof color != 'object' || typeof color.name != 'string' || typeof color.color != 'string') { + Zotero.logError("Removing invalid colored tag: " + JSON.stringify(color)); + tagsFixed = true; + return false; + } + return true; + }); + // Before whitespace was trimmed in Tags.setColor() in 5.0.75 + tagColors.forEach((tag) => { + let trimmed = tag.name.trim(); + if (trimmed != tag.name) { + tag.name = trimmed; + fixed = true; + } + }); + if (fixed) { + await this.set(libraryID, 'tagColors', tagColors); + } + } + }, /** * Return settings object