diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index ef2835fff2..45d736deb7 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -1008,8 +1008,3 @@ Zotero.Collection.prototype._refreshChildItems = Zotero.Promise.coroutine(functi return this.loadChildItems(true); } }); - - -Zotero.Collection.prototype._generateKey = function () { - return Zotero.Utilities.generateObjectKey(); -} diff --git a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js index 0f1172abf2..7391d465e3 100644 --- a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js +++ b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js @@ -27,17 +27,32 @@ Zotero.DataObjectUtilities = { "checkLibraryID": function (libraryID) { if (libraryID === null) { - Zotero.debug("Deprecated: libraryID cannot be NULL\n\n" + Components.stack, 2); + Zotero.debug("Deprecated: libraryID cannot be NULL", 2, 1); } else { var intValue = parseInt(libraryID); - if (libraryID != intValue) { - throw new Error("libraryID must be an integer"); + if (libraryID != intValue || intValue < 0) { + throw new Error("libraryID must be a positive integer"); } } return intValue; }, + "checkDataID": function(dataID) { + var intValue = parseInt(dataID); + if (dataID != intValue || dataID < 0) + throw new Error("id must be a positive integer"); + return intValue; + }, + + "checkKey": function(key) { + if (!key) return null; + if (!Zotero.Utilities.isValidObjectKey(key)) { + throw new Error("key is not valid"); + } + return key; + }, + "getObjectTypePlural": function getObjectTypePlural(objectType) { return objectType == 'search' ? 'searches' : objectType + 's'; }, diff --git a/chrome/content/zotero/xpcom/id.js b/chrome/content/zotero/xpcom/id.js index 8db03966a1..4387a963ab 100644 --- a/chrome/content/zotero/xpcom/id.js +++ b/chrome/content/zotero/xpcom/id.js @@ -83,13 +83,6 @@ Zotero.ID_Tracker = function () { } }); - - this.isValidKey = function (value) { - var re = /^[23456789ABCDEFGHIJKLMNPQRSTUVWXYZ]{8}$/ - return re.test(value); - } - - function getBigInt(max) { if (!max) { max = 9007199254740991; diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index 6f706c1aa1..b7b57e2f5a 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -1642,13 +1642,6 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { this._sqlParams = sqlParams.length ? sqlParams : false; }); - -Zotero.Search.prototype._generateKey = function () { - return Zotero.Utilities.generateObjectKey(); -} - - - Zotero.Searches = new function(){ Zotero.DataObjects.apply(this, ['search', 'searches', 'savedSearch', 'savedSearches']); this.constructor.prototype = new Zotero.DataObjects(); diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 91b223be86..8649d3c285 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1812,16 +1812,26 @@ Zotero.Utilities = { return Zotero.ItemTypes.getImageSrc(attachment.mimeType === "application/pdf" ? "attachment-pdf" : "attachment-snapshot"); }, - + + "allowedKeyChars": "23456789ABCDEFGHIJKLMNPQRSTUVWXYZ", + /** * Generates a valid object key for the server API */ "generateObjectKey":function generateObjectKey() { - // TODO: add 'L' and 'Y' after 3.0.11 cut-off - var baseString = "23456789ABCDEFGHIJKMNPQRSTUVWXZ"; - return Zotero.Utilities.randomString(8, baseString); + return Zotero.Utilities.randomString(8, Zotero.Utilities.allowedKeyChars); }, - + + /** + * Check if an object key is in a valid format + */ + "isValidObjectKey":function(key) { + if (!Zotero.Utilities.objectKeyRegExp) { + Zotero.Utilities.objectKeyRegExp = new RegExp('^[' + Zotero.Utilities.allowedKeyChars + ']{8}$'); + } + return Zotero.Utilities.objectKeyRegExp.test(key); + }, + /** * Provides unicode support and other additional features for regular expressions * See https://github.com/slevithan/xregexp for usage