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); 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;