www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 2cd8ac04e23cc331211917723473bb62d91466b2
parent ce1b3e099aaf451f22ef2d0fab1c521f1005badc
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon, 18 Jul 2011 21:57:15 +0000

Stringify invalid objects when saving items


Diffstat:
Mchrome/content/zotero/xpcom/translation/translate.js | 27++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js @@ -87,19 +87,28 @@ Zotero.Translate.Sandbox = { if(translate._complete) { Zotero.debug("Translate: WARNING: Zotero.Item#complete() called after Zotero.done(); please fix your code", 2); } + + const allowedObjects = ["complete", "attachments", "seeAlso", "creators", "tags", "notes"]; + + for(var i in item) { + var val = item[i]; + var type = typeof val; + if(!val && val !== 0) { + // remove null, undefined, and false properties, and convert objects to strings + delete item[i]; + } else if(type === "string") { + // trim strings + item[i] = val.trim(); + } else if((type === "object" || type === "xml") && allowedObjects.indexOf(i) === -1) { + // convert things that shouldn't be objecst to objects + translate._debug("Translate: WARNING: typeof "+i+" is "+type+"; converting to string"); + item[i] = val.toString(); + } + } // if we're not supposed to save the item or we're in a child translator, // just return the item array if(translate._libraryID === false || translate._parentTranslator) { - // remove null, undefined, and false properties - for(var i in item) { - if(!item[i] && item[i] !== 0) { - delete item[i]; - } else if(typeof item[i] === "string") { - item[i] = item[i].trim(); - } - } - translate.newItems.push(item); translate._runHandler("itemDone", item, item); return;