commit 2f8f18c9571010b5f9d9035f62b590e63ffc1e4f parent b7c0427167b0df5d28754bf9e7b8b38e724c41a6 Author: Simon Kornblith <simon@simonster.com> Date: Sun, 10 Mar 2013 16:16:51 -0400 Ensure that arrays are not strings Diffstat:
| M | chrome/content/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 @@ -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(); } }