From 8c338675d210fdaab5f866092834a0c5902efc6f Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 25 May 2020 09:52:10 +0100 Subject: [PATCH] Desktop: Fixes #3267: Fixed issue with invalid image paths when config path contains spaces --- CliClient/tests/markdownUtils.js | 15 +++++++++++++++ ReactNativeClient/lib/joplin-renderer/MdToHtml.js | 2 -- ReactNativeClient/lib/markdownUtils.js | 1 + ReactNativeClient/lib/models/Note.js | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CliClient/tests/markdownUtils.js b/CliClient/tests/markdownUtils.js index 9328ca645..9158ba96a 100644 --- a/CliClient/tests/markdownUtils.js +++ b/CliClient/tests/markdownUtils.js @@ -51,6 +51,21 @@ describe('markdownUtils', function() { } })); + it('escape a markdown link', asyncTest(async () => { + + const testCases = [ + ['file:///Users/who put spaces in their username??/.config/joplin', 'file:///Users/who%20put%20spaces%20in%20their%20username??/.config/joplin'], + ['file:///Users/(and brackets???)/.config/joplin', 'file:///Users/%28and%20brackets???%29/.config/joplin'], + ['file:///Users/thisisfine/.config/joplin', 'file:///Users/thisisfine/.config/joplin'], + ]; + + for (let i = 0; i < testCases.length; i++) { + const md = testCases[i][0]; + const expected = testCases[i][1]; + expect(markdownUtils.escapeLinkUrl(md)).toBe(expected); + } + })); + it('escape a markdown link (title)', asyncTest(async () => { const testCases = [ diff --git a/ReactNativeClient/lib/joplin-renderer/MdToHtml.js b/ReactNativeClient/lib/joplin-renderer/MdToHtml.js index 0699ce13d..32ab6b059 100644 --- a/ReactNativeClient/lib/joplin-renderer/MdToHtml.js +++ b/ReactNativeClient/lib/joplin-renderer/MdToHtml.js @@ -178,8 +178,6 @@ class MdToHtml { // files. Otherwise some of them might be in the cssStrings property. externalAssetsOnly: false, postMessageSyntax: 'postMessage', - // paddingTop: '0', - // paddingBottom: '0', highlightedKeywords: [], codeTheme: 'atom-one-light.css', theme: Object.assign({}, defaultNoteStyle, theme), diff --git a/ReactNativeClient/lib/markdownUtils.js b/ReactNativeClient/lib/markdownUtils.js index 0893754a3..36c0b4aab 100644 --- a/ReactNativeClient/lib/markdownUtils.js +++ b/ReactNativeClient/lib/markdownUtils.js @@ -18,6 +18,7 @@ const markdownUtils = { escapeLinkUrl(url) { url = url.replace(/\(/g, '%28'); url = url.replace(/\)/g, '%29'); + url = url.replace(/ /g, '%20'); return url; }, diff --git a/ReactNativeClient/lib/models/Note.js b/ReactNativeClient/lib/models/Note.js index 091bbf83b..0d2608984 100644 --- a/ReactNativeClient/lib/models/Note.js +++ b/ReactNativeClient/lib/models/Note.js @@ -149,7 +149,7 @@ class Note extends BaseItem { const resource = await Resource.load(id); if (!resource) continue; const resourcePath = options.useAbsolutePaths ? `file://${Resource.fullPath(resource)}` : Resource.relativePath(resource); - body = body.replace(new RegExp(`:/${id}`, 'gi'), resourcePath); + body = body.replace(new RegExp(`:/${id}`, 'gi'), markdownUtils.escapeLinkUrl(resourcePath)); } this.logger().info('replaceResourceInternalToExternalLinks result', body);