From 4b09137402ebbaa5ebfdb4ca26cfb704c5280211 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Fri, 23 Nov 2012 23:06:05 -0600 Subject: [PATCH 1/2] Call complete() when no translators are set. Don't fail when a translator returns without throwing an error or completing an item. --- chrome/content/zotero/xpcom/translation/translate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index ac2dd7f02..2ae8355f9 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1045,7 +1045,7 @@ Zotero.Translate.Base.prototype = { this._currentState = "translate"; if(!this.translator || !this.translator.length) { - throw new Error("Failed: no translator specified"); + this.complete(false, new Error("No translator specified")); } this._libraryID = libraryID; @@ -2093,8 +2093,8 @@ Zotero.Translate.Search.prototype.setTranslator = function(translator) { */ Zotero.Translate.Search.prototype.complete = function(returnValue, error) { if(this._currentState == "translate" && (!this.newItems || !this.newItems.length)) { - Zotero.debug("Translate: Could not find a result using "+this.translator[0].label+": \n" - +this._generateErrorString(error), 3); + Zotero.debug("Translate: Could not find a result using "+this.translator[0].label, 3); + if(error) Zotero.debug(this._generateErrorString(error), 3); if(this.translator.length > 1) { this.translator.shift(); this.translate(this._libraryID, this._saveAttachments); From 524af03570c8502e92e0b44f104b273080de9969 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Fri, 23 Nov 2012 23:06:47 -0600 Subject: [PATCH 2/2] Make cleanISBN less aggressive. Should yield fewer false-positives. --- chrome/content/zotero/xpcom/utilities.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index a5622c66f..e2f3cab5b 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -277,7 +277,10 @@ Zotero.Utilities = { * Return isbn if valid, otherwise return false */ "cleanISBN":function(/**String*/ isbn) { - isbn = isbn.replace(/[^x\d]+/ig, '').toUpperCase(); + isbn = isbn.replace(/[^0-9a-z]+/ig, '').toUpperCase() //we only want to ignore punctuation, spaces + .match(/(?:97[89][0-9]{10}|[0-9]{9}[0-9X])/); //13 digit or 10 digit + if(!isbn) return false; + isbn = isbn[0]; if(isbn.length == 10) { // Verify ISBN-10 checksum @@ -292,17 +295,11 @@ Zotero.Utilities = { return (sum % 11 == 0) ? isbn : false; } - isbn = isbn.replace(/X/g, ''); //get rid of Xs - if(isbn.length == 13) { - // ISBN-13 should start with 978 or 979 i.e. GS1 for book publishing industry - var prefix = isbn.slice(0,3); - if (prefix != "978" && prefix != "979") return false; - // Verify checksum var sum = 0; for (var i = 0; i < 12; i+=2) sum += isbn[i]*1; //to make sure it's int - for (i = 1; i < 12; i+=2) sum += isbn[i]*3; + for (var i = 1; i < 12; i+=2) sum += isbn[i]*3; sum += isbn[12]*1; //add the check digit return (sum % 10 == 0 )? isbn : false;