From c549166e2585a8a6e3ac0d8c6aa0d0fa87783685 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 21 Jul 2012 21:12:59 -0400 Subject: [PATCH 1/2] Fix XMLSerializer on older Firefox versions --- chrome/content/zotero/xpcom/translation/translate_firefox.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index d1154ef639..b68c1d882b 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -85,6 +85,8 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) { return s.serializeToString(doc.__wrappedDOMObject ? doc.__wrappedDOMObject : doc); }; }; + this.sandbox.XMLSerializer.__exposedProps__ = {"prototype":"r"}; + this.sandbox.XMLSerializer.prototype = {}; } /** From 70440ee8f949b3fdce9c3779277cb780b082b281 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 23 Jul 2012 23:47:58 -0400 Subject: [PATCH 2/2] Don't sanitize input from child web translators before passing it to parent translators --- .../zotero/xpcom/translation/translate.js | 125 +++++++++--------- 1 file changed, 64 insertions(+), 61 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index a45a5cfa21..aca9cca686 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -522,73 +522,76 @@ Zotero.Translate.Sandbox = { * @param {SandboxItem} An item created using the Zotero.Item class from the sandbox */ "_itemDone":function(translate, item) { - if(!item.itemType) { - item.itemType = "webpage"; - translate._debug("WARNING: No item type specified"); - } - - if(item.type == "attachment" || item.type == "note") { - Zotero.debug("Translate: Discarding standalone "+item.type+" in non-import translator", 2); - return; - } - - // store library catalog if this item was captured from a website, and - // libraryCatalog is truly undefined (not false or "") - if(item.repository !== undefined) { - Zotero.debug("Translate: 'repository' field is now 'libraryCatalog'; please fix your code", 2); - item.libraryCatalog = item.repository; - delete item.repository; - } - - // automatically set library catalog - if(item.libraryCatalog === undefined) { - item.libraryCatalog = translate.translator[0].label; - } - - // automatically set access date if URL is set - if(item.url && typeof item.accessDate == 'undefined') { - item.accessDate = "CURRENT_TIMESTAMP"; - } - - if(!item.title) { - translate.complete(false, new Error("No title specified for item")); - return; - } - - // create short title - if(item.shortTitle === undefined && Zotero.Utilities.fieldIsValidForType("shortTitle", item.itemType)) { - // only set if changes have been made - var setShortTitle = false; - var title = item.title; - - // shorten to before first colon - var index = title.indexOf(":"); - if(index !== -1) { - title = title.substr(0, index); - setShortTitle = true; + // Only apply checks if there is no parent translator + if(!translate._parentTranslator) { + if(!item.itemType) { + item.itemType = "webpage"; + translate._debug("WARNING: No item type specified"); } - // shorten to after first question mark - index = title.indexOf("?"); - if(index !== -1) { - index++; - if(index != title.length) { + + if(item.type == "attachment" || item.type == "note") { + Zotero.debug("Translate: Discarding standalone "+item.type+" in non-import translator", 2); + return; + } + + // store library catalog if this item was captured from a website, and + // libraryCatalog is truly undefined (not false or "") + if(item.repository !== undefined) { + Zotero.debug("Translate: 'repository' field is now 'libraryCatalog'; please fix your code", 2); + item.libraryCatalog = item.repository; + delete item.repository; + } + + // automatically set library catalog + if(item.libraryCatalog === undefined) { + item.libraryCatalog = translate.translator[0].label; + } + + // automatically set access date if URL is set + if(item.url && typeof item.accessDate == 'undefined') { + item.accessDate = "CURRENT_TIMESTAMP"; + } + + if(!item.title) { + translate.complete(false, new Error("No title specified for item")); + return; + } + + // create short title + if(item.shortTitle === undefined && Zotero.Utilities.fieldIsValidForType("shortTitle", item.itemType)) { + // only set if changes have been made + var setShortTitle = false; + var title = item.title; + + // shorten to before first colon + var index = title.indexOf(":"); + if(index !== -1) { title = title.substr(0, index); setShortTitle = true; } + // shorten to after first question mark + index = title.indexOf("?"); + if(index !== -1) { + index++; + if(index != title.length) { + title = title.substr(0, index); + setShortTitle = true; + } + } + + if(setShortTitle) item.shortTitle = title; } - if(setShortTitle) item.shortTitle = title; - } - - // refuse to save very long tags - if(item.tags) { - for(var i=0; i 255) { - translate._debug("WARNING: Skipping unsynchable tag "+JSON.stringify(tagString)); - item.tags.splice(i--, 1); + // refuse to save very long tags + if(item.tags) { + for(var i=0; i 255) { + translate._debug("WARNING: Skipping unsynchable tag "+JSON.stringify(tagString)); + item.tags.splice(i--, 1); + } } } }