From a84bc2350b411f08d12de65e97d207bc916581cc Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 10 Dec 2019 15:47:52 -0600 Subject: [PATCH 1/2] Changed the regex that matches the image path in removeStorageAndNoteReferences --- browser/main/lib/dataApi/attachmentManagement.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 971ae8128..cab4e8c9c 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -560,7 +560,8 @@ function replaceNoteKeyWithNewNoteKey (noteContent, oldNoteKey, newNoteKey) { * @returns {String} Input without the references */ function removeStorageAndNoteReferences (input, noteKey) { - return input.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|])', 'g'), function (match) { + const possibleSeparators = new RegExp('(' + escapeStringRegexp(path.posix.sep) + '|' + escapeStringRegexp(path.win32.sep) + '|' + mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep) + ')') + return input.replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + possibleSeparators.source + noteKey + possibleSeparators.source + ')?', 'g'), function (match) { const temp = match .replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.sep) .replace(new RegExp(mdurl.encode(path.posix.sep), 'g'), path.sep) From 9792bc48ee96048d365684b3bb7aca5f95a86d71 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 10 Dec 2019 15:53:30 -0600 Subject: [PATCH 2/2] Changed test in attachmentManagement.test.js in order to test with and expect the correct format --- tests/dataApi/attachmentManagement.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js index 13dcedcad..c712c6ecb 100644 --- a/tests/dataApi/attachmentManagement.test.js +++ b/tests/dataApi/attachmentManagement.test.js @@ -470,13 +470,13 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c const noteKey = 'noteKey' const testInput = 'Test input' + - '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + noteKey + path.win32.sep + 'image.jpg](imageName}) \n' + - '[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + noteKey + path.posix.sep + 'pdf.pdf](pdf})' + '![imageName](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + noteKey + path.win32.sep + 'image.jpg) \n' + + '[pdf](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + noteKey + path.posix.sep + 'pdf.pdf)' const expectedOutput = 'Test input' + - '![' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'image.jpg](imageName}) \n' + - '[' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'pdf.pdf](pdf})' + '![imageName](' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'image.jpg) \n' + + '[pdf](' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'pdf.pdf)' const actual = systemUnderTest.removeStorageAndNoteReferences(testInput, noteKey) expect(actual).toEqual(expectedOutput) })