From 1d1ab65edd61d5b0c8056795d59d11c112c62c55 Mon Sep 17 00:00:00 2001 From: Maciek Date: Sat, 28 Jul 2018 22:23:14 +0200 Subject: [PATCH 1/2] BUG FIX: snippet notes are not displaying in markdown #2088 Fix for issue https://github.com/BoostIo/Boostnote/issues/2088. In specific situation, when all below conditions are met : - one of the snippets notes tabs is a Markdown tab, - the migrateAttachments code is called on a snippet note, - historical attachments location '/images' exists in snippet storage folder Following exception is being thrown : path.js:28 Uncaught TypeError: Path must be a string. Received undefined The exception is a result of an undefined noteKey variable (which is defined only for Markdown notes). The solution is to skip migration of attachments for notes without noteKey (which wouldn't be possible anyway, since noteKey is a necessary for creating folder for attachments). --- browser/main/lib/dataApi/attachmentManagement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 088fb054..46560a1a 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -82,7 +82,7 @@ function createAttachmentDestinationFolder (destinationStoragePath, noteKey) { * @param noteKey Key of the current note */ function migrateAttachments (markdownContent, storagePath, noteKey) { - if (sander.existsSync(path.join(storagePath, 'images'))) { + if (noteKey !== undefined && sander.existsSync(path.join(storagePath, 'images'))) { const attachments = getAttachmentsInMarkdownContent(markdownContent) || [] if (attachments !== []) { createAttachmentDestinationFolder(storagePath, noteKey) From 4a3bcaba0657dd17e4494ebb94122de85e15c617 Mon Sep 17 00:00:00 2001 From: Maciek Date: Sat, 28 Jul 2018 22:25:10 +0200 Subject: [PATCH 2/2] BUG FIX: Change the way of checking for empty array The original condition : attachments !== [] always returns true, for empty array, as well as for array with elements. --- browser/main/lib/dataApi/attachmentManagement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 46560a1a..d1e0ab62 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -84,7 +84,7 @@ function createAttachmentDestinationFolder (destinationStoragePath, noteKey) { function migrateAttachments (markdownContent, storagePath, noteKey) { if (noteKey !== undefined && sander.existsSync(path.join(storagePath, 'images'))) { const attachments = getAttachmentsInMarkdownContent(markdownContent) || [] - if (attachments !== []) { + if (attachments.length) { createAttachmentDestinationFolder(storagePath, noteKey) } for (const attachment of attachments) {