From 2f8f18c9571010b5f9d9035f62b590e63ffc1e4f Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 10 Mar 2013 16:16:51 -0400 Subject: [PATCH] Ensure that arrays are not strings --- .../zotero/xpcom/translation/translate.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index d95ef2e312..38b9f5da29 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -93,17 +93,24 @@ Zotero.Translate.Sandbox = { delete item.complete; 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" || type === "function") && allowedObjects.indexOf(i) === -1) { - // convert things that shouldn't be objecst to objects + continue; + } + + var isObject = typeof val === "object" || typeof val === "xml" || typeof val === "function", + shouldBeObject = allowedObjects.indexOf(i) !== -1; + if(isObject && !shouldBeObject) { + // Convert things that shouldn't be objects to objects translate._debug("Translate: WARNING: typeof "+i+" is "+type+"; converting to string"); item[i] = val.toString(); + } else if(shouldBeObject && !isObject) { + translate._debug("Translate: WARNING: typeof "+i+" is "+type+"; converting to array"); + item[i] = [val]; + } else if(typeof val === "string") { + // trim strings + item[i] = val.trim(); } }