From 7e23cfef96eece450090652dadc72f6b64a3d19b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 14 May 2021 04:17:51 -0400 Subject: [PATCH] Fix invalid imported Mendeley annotation color After fix in 808b71832e And require annotation colors to be 6-char hex colors going forward --- chrome/content/zotero/xpcom/data/item.js | 9 +++++++++ chrome/content/zotero/xpcom/schema.js | 4 ++++ resource/schema/userdata.sql | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index a53874267f..3c8d35bdf0 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3706,6 +3706,15 @@ for (let name of ['type', 'text', 'comment', 'color', 'pageLabel', 'sortIndex', } break; + case 'color': + // Require 6-char hex value + if (!value.match(/#[a-f0-9]{6}/)) { + let e = new Error(`Invalid annotation color '${value}'`); + e.name = "ZoteroInvalidDataError"; + throw e; + } + break; + case 'sortIndex': if (!/^\d{5}\|\d{6}\|\d{5}$/.test(value)) { throw new Error(`Invalid sortIndex '${value}`); diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index e6d02ef805..100b214f66 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -3268,6 +3268,10 @@ Zotero.Schema = new function(){ yield Zotero.DB.queryAsync("DELETE FROM items WHERE itemTypeID=? AND itemID NOT IN (SELECT itemID FROM itemAnnotations)", annotationID); } + else if (i == 114) { + yield Zotero.DB.queryAsync("UPDATE itemAnnotations SET color='#ffff00' WHERE color='#ffff0'"); + } + // If breaking compatibility or doing anything dangerous, clear minorUpdateFrom } diff --git a/resource/schema/userdata.sql b/resource/schema/userdata.sql index ab0b4e3288..f3e0da572a 100644 --- a/resource/schema/userdata.sql +++ b/resource/schema/userdata.sql @@ -1,4 +1,4 @@ --- 113 +-- 114 -- Copyright (c) 2009 Center for History and New Media -- George Mason University, Fairfax, Virginia, USA