From 5238b4d5039d00bc2971c7f2e0e209a2c667bded Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 5 Feb 2016 23:05:24 +0000 Subject: [PATCH] Evernote plugin: fix crash with missing fields --- .../evernote/modules/enex-deserializer.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/tiddlywiki/evernote/modules/enex-deserializer.js b/plugins/tiddlywiki/evernote/modules/enex-deserializer.js index f01156541..3a4a2e96b 100644 --- a/plugins/tiddlywiki/evernote/modules/enex-deserializer.js +++ b/plugins/tiddlywiki/evernote/modules/enex-deserializer.js @@ -35,10 +35,10 @@ exports["application/enex+xml"] = function(text,fields) { var noteNodes = doc.querySelectorAll("note"); $tw.utils.each(noteNodes,function(noteNode) { var result = { - title: noteNode.querySelector("title").textContent, + title: getTextContent(noteNode,"title"), type: "text/html", tags: [], - text: noteNode.querySelector("content").textContent + text: getTextContent(noteNode,"content") }; $tw.utils.each(noteNode.querySelectorAll("tag"),function(tagNode) { result.tags.push(tagNode.textContent); @@ -49,11 +49,11 @@ exports["application/enex+xml"] = function(text,fields) { results.push(result); $tw.utils.each(noteNode.querySelectorAll("resources"),function(resourceNode) { results.push({ - title: resourceNode.querySelector("resource-attributes>file-name").textContent, - type: resourceNode.querySelector("mime").textContent, - width: resourceNode.querySelector("width").textContent, - height: resourceNode.querySelector("height").textContent, - text: resourceNode.querySelector("data").textContent + title: getTextContent(resourceNode,"resource-attributes>file-name"), + type: getTextContent(resourceNode,"mime"), + width: getTextContent(resourceNode,"width"), + height: getTextContent(resourceNode,"height"), + text: getTextContent(resourceNode,"data") }); }); }); @@ -61,4 +61,8 @@ exports["application/enex+xml"] = function(text,fields) { return results; }; +function getTextContent(node,selector) { + return (node.querySelector(selector) || {}).textContent; +} + })();