From fed9fe597da0b69cfcc564d6bcdebc1329ae8188 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Mon, 12 Nov 2012 03:19:29 -0600 Subject: [PATCH 01/12] Allow translators to pre-select items in the "multiple" select item dialog. --- chrome/content/zotero/ingester/selectitems.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/ingester/selectitems.js b/chrome/content/zotero/ingester/selectitems.js index 4118b790b..32c01596c 100644 --- a/chrome/content/zotero/ingester/selectitems.js +++ b/chrome/content/zotero/ingester/selectitems.js @@ -47,11 +47,21 @@ Zotero_Ingester_Interface_SelectItems.init = function() { var listbox = document.getElementById("zotero-selectitems-links"); for(var i in this.io.dataIn) { // we could use a tree for this if we wanted to + var item = this.io.dataIn[i]; + + var title, checked = false; + if(typeof(item) != "string" && item.title != undefined) { + title = item.title; + checked = !!item.checked; + } else { + title = item; + } + var itemNode = document.createElement("listitem"); itemNode.setAttribute("type", "checkbox"); itemNode.setAttribute("value", i); - itemNode.setAttribute("label", this.io.dataIn[i]); - itemNode.setAttribute("checked", false); + itemNode.setAttribute("label", title); + itemNode.setAttribute("checked", checked); listbox.appendChild(itemNode); } } From 9c92f50fab89ae6254833143f20faffd2eb70171 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Mon, 12 Nov 2012 11:12:39 -0600 Subject: [PATCH 02/12] Avoid potential exceptions --- chrome/content/zotero/ingester/selectitems.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/ingester/selectitems.js b/chrome/content/zotero/ingester/selectitems.js index 32c01596c..8f639248c 100644 --- a/chrome/content/zotero/ingester/selectitems.js +++ b/chrome/content/zotero/ingester/selectitems.js @@ -50,7 +50,7 @@ Zotero_Ingester_Interface_SelectItems.init = function() { var item = this.io.dataIn[i]; var title, checked = false; - if(typeof(item) != "string" && item.title != undefined) { + if(item && typeof(item) == "object" && item.title !== undefined) { title = item.title; checked = !!item.checked; } else { From b9cc4496b96a68fce3196450741f11a2e64c2dc3 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Mon, 12 Nov 2012 11:43:51 -0600 Subject: [PATCH 03/12] Fix translator tester --- .../zotero/tools/testTranslators/translatorTester.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/tools/testTranslators/translatorTester.js b/chrome/content/zotero/tools/testTranslators/translatorTester.js index 9cd292ef0..01a07a349 100644 --- a/chrome/content/zotero/tools/testTranslators/translatorTester.js +++ b/chrome/content/zotero/tools/testTranslators/translatorTester.js @@ -422,7 +422,11 @@ Zotero_TranslatorTester.prototype.runTest = function(test, doc, testDoneCallback var newItems = {}; var haveItems = false; for(var i in items) { - newItems[i] = items[i]; + if(items[i] && typeof(items[i]) == "object" && items[i].title !== undefined) { + newItems[i] = items[i].title; + } else { + newItems[i] = items[i]; + } haveItems = true; // only save one item if "items":"multiple" (as opposed to an array of items) @@ -546,7 +550,11 @@ Zotero_TranslatorTester.prototype.newTest = function(doc, testReadyCallback) { var newItems = {}; for(var i in items) { - newItems[i] = items[i]; + if(items[i] && typeof(items[i]) == "object" && items[i].title !== undefined) { + newItems[i] = items[i].title; + } else { + newItems[i] = items[i]; + } break; } From 63f1dd163de0ccd9c21af4f1efc54d9d447a0c94 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Sun, 25 Nov 2012 05:05:52 -0600 Subject: [PATCH 04/12] Make varDump more resilient to property access errors --- chrome/content/zotero/xpcom/utilities.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index f9b9b8f27..a5622c66f 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1092,11 +1092,11 @@ Zotero.Utilities = { */ "varDump":function(arr,level,maxLevel,parentObjects,path) { var dumped_text = ""; - if (!level){ + if (level === undefined){ level = 0; } - if (!maxLevel) { + if (maxLevel === undefined) { maxLevel = 4; } @@ -1119,7 +1119,12 @@ Zotero.Utilities = { } for (var item in arr) { - var value = arr[item]; + try { + var value = arr[item]; + } catch(e) { + dumped_text += level_padding + "'" + item + "' => <>\n"; + continue; + } if (typeof(value) == 'object') { // If it is an array //check for recursion @@ -1139,9 +1144,13 @@ Zotero.Utilities = { dumped_text += level_padding + "'" + item + "' => " + openBrace; //only recurse if there's anything in the object, purely cosmetical - for(var i in value) { - dumped_text += "\n" + Zotero.Utilities.varDump(value,level+1,maxLevel,parentObjects.concat([value]),path.concat([item])) + level_padding; - break; + try { + for(var i in value) { + dumped_text += "\n" + Zotero.Utilities.varDump(value,level+1,maxLevel,parentObjects.concat([value]),path.concat([item])) + level_padding; + break; + } + } catch(e) { + dumped_text += "<>\n"; } dumped_text += closeBrace + "\n"; } From 2e4a21857579922715e7227b76312157733c1006 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 25 Nov 2012 16:26:09 -0500 Subject: [PATCH 05/12] Fix cross-domain wrapping under most circumstances. Cross-domain wrapping was previously broken when a page loaded a page from a different SOP, which then loaded another page. Thanks to @aurimasv for debugging this. It's still broken if one page sets document.domain and another does not, since we should wrap in this case but we won't. Fixes #202 --- chrome/content/zotero/xpcom/utilities_translate.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities_translate.js b/chrome/content/zotero/xpcom/utilities_translate.js index 8be8830a8..3d1df5a40 100644 --- a/chrome/content/zotero/xpcom/utilities_translate.js +++ b/chrome/content/zotero/xpcom/utilities_translate.js @@ -227,15 +227,13 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor } if(Zotero.isFx) { - var translate = this._translate; - if(translate.document) { - var protocol = translate.document.location.protocol, - host = translate.document.location.host; - } else { + if(typeof translate._sandboxLocation === "object") { + var protocol = translate._sandboxLocation.location.protocol, + host = translate._sandboxLocation.location.host; + } else { var url = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService) - .newURI(typeof translate._sandboxLocation === "object" ? - translate._sandboxLocation.location : translate._sandboxLocation, null, null), + .newURI(translate._sandboxLocation, null, null), protocol = url.scheme+":", host = url.host; } From 5a4b280dad05e105f6616ee76ed970b0225edbcf Mon Sep 17 00:00:00 2001 From: aurimasv Date: Tue, 27 Nov 2012 16:33:49 -0600 Subject: [PATCH 06/12] Use the last version of the page for translation. --- chrome/content/zotero/browser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index e02fcfe1a..8d12f0869 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -794,7 +794,8 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla // if there's already a scrapable page in the browser window, and it's // still there, ensure it is actually part of the page, then return if(this.page.translators && this.page.translators.length && this.page.document.location) { - if(this.page.document.defaultView && !this.page.document.defaultView.closed) { + if(this.page.document.defaultView && !this.page.document.defaultView.closed + && this.page.document.location.href != translate.document.location.href) { // if it is still there, switch translation to take place on if(!translators.length || this.page.translators[0].priority <= translators[0].priority) return; } else { From 7bf31afa8c3552c9f6248736e9071c97becf3a64 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Sat, 1 Dec 2012 01:38:49 -0600 Subject: [PATCH 07/12] Pass url to detect function --- chrome/content/zotero/xpcom/server_connector.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js index e8312cbfd..193812965 100755 --- a/chrome/content/zotero/xpcom/server_connector.js +++ b/chrome/content/zotero/xpcom/server_connector.js @@ -187,9 +187,9 @@ Zotero.Server.Connector.SavePage.prototype = { * @param {Object} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { this.sendResponse = sendResponseCallback; - Zotero.Server.Connector.Detect.prototype.init.apply(this, [data, sendResponseCallback]) + Zotero.Server.Connector.Detect.prototype.init.apply(this, [url, data, sendResponseCallback]) }, /** From ab564ed7ca7ce04534e0e3bec1d023f0ffbb04bc Mon Sep 17 00:00:00 2001 From: aurimasv Date: Sat, 1 Dec 2012 18:33:35 -0600 Subject: [PATCH 08/12] [PDF metadata retrieval] Fix broken DOI scanning --- chrome/content/zotero/recognizePDF.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/recognizePDF.js b/chrome/content/zotero/recognizePDF.js index ffdf22238..d36d90f76 100644 --- a/chrome/content/zotero/recognizePDF.js +++ b/chrome/content/zotero/recognizePDF.js @@ -310,7 +310,7 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c Zotero.debug(allText); var m = Zotero.Utilities.cleanDOI(allText); if(m) { - this._DOI = m[0]; + this._DOI = m; } // Use only first column from multi-column lines From 07bcccd92e6816417867dfb441c1349439223284 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Mon, 10 Dec 2012 20:07:56 -0600 Subject: [PATCH 09/12] [WebPageDump] Don't crash when @import stylesheets are null (caused by adblock) --- chrome/content/zotero/webpagedump/domsaver.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/webpagedump/domsaver.js b/chrome/content/zotero/webpagedump/domsaver.js index d7b38d6ea..011bd64c6 100644 --- a/chrome/content/zotero/webpagedump/domsaver.js +++ b/chrome/content/zotero/webpagedump/domsaver.js @@ -633,7 +633,7 @@ var wpdDOMSaver = { // FONT_FACE_RULE = 5, // PAGE_RULE = 6 processCSSRecursively: function (aCSS) { - if (aCSS.disabled) return ""; + if (!aCSS || aCSS.disabled) return ""; var content = ""; var medium = aCSS.media.mediaText; if (medium != "" && medium.indexOf("screen") < 0 && medium.indexOf("all") < 0) { @@ -966,8 +966,9 @@ var wpdDOMSaver = { if (this.option["format"]) { var myStyleSheets = aDocument.styleSheets; // get all style sheets to "CSSText" - for (var i = 0; i < myStyleSheets.length; i++) - CSSText += this.processCSSRecursively(myStyleSheets[i]); + for (var i = 0; i < myStyleSheets.length; i++) { + CSSText += this.processCSSRecursively(myStyleSheets[i]); + } if (CSSText) { // don't forget to convert the CSS String to the document charset.. // (necessary for e.g. font-family) From 4b09137402ebbaa5ebfdb4ca26cfb704c5280211 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Fri, 23 Nov 2012 23:06:05 -0600 Subject: [PATCH 10/12] 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 11/12] 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; From 040fa318877a4d22bb8f692f7410e7939398d583 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Wed, 19 Dec 2012 21:00:10 -0500 Subject: [PATCH 12/12] Fix issue reported at http://forums.zotero.org/discussion/26922/ Since we still use E4X, this is a hack to make sure the span tag has a separate close tag. --- chrome/content/zotero/xpcom/cite.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index cc5c5c762..baed5d74c 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -265,7 +265,7 @@ Zotero.Cite.makeFormattedBibliography = function(cslEngine, format) { if(!co) continue; output.push(' ", ">", "g")+ - '"/>\n'); + '"/>\n'); } catch(e) { Zotero.logError(e); } @@ -378,7 +378,7 @@ Zotero.Cite.makeFormattedBibliography = function(cslEngine, format) { } //Zotero.debug(xml); - str = xml.toXMLString(); + str = xml.toXMLString().replace("/>", ">", "g"); } finally { XML.prettyPrinting = true; XML.ignoreWhitespace = true;