From 461e24bf39630b0807632e901a72ae7678cddcd6 Mon Sep 17 00:00:00 2001 From: Junyoung Choi Date: Thu, 16 Apr 2020 00:07:45 +0900 Subject: [PATCH] Fix regex --- .../main/lib/dataApi/attachmentManagement.js | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index f59a7ef3..48500f4a 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -713,24 +713,30 @@ function replaceNoteKeyWithNewNoteKey(noteContent, oldNoteKey, newNoteKey) { */ function removeStorageAndNoteReferences(input, noteKey) { return input.replace( - new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|])', 'g'), + new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|\\))', '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) - .replace(new RegExp(escapeStringRegexp(path.win32.sep), 'g'), path.sep) - .replace(new RegExp(escapeStringRegexp(path.posix.sep), 'g'), path.sep) - return temp.replace( - new RegExp( - STORAGE_FOLDER_PLACEHOLDER + - '(' + - escapeStringRegexp(path.sep) + - noteKey + - ')?', - 'g' - ), - DESTINATION_FOLDER - ) + return match + .replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.posix.sep) + .replace(new RegExp(mdurl.encode(path.posix.sep), 'g'), path.posix.sep) + .replace( + new RegExp(escapeStringRegexp(path.win32.sep), 'g'), + path.posix.sep + ) + .replace( + new RegExp(escapeStringRegexp(path.posix.sep), 'g'), + path.posix.sep + ) + .replace( + new RegExp( + STORAGE_FOLDER_PLACEHOLDER + + '(' + + escapeStringRegexp(path.sep) + + noteKey + + ')?', + 'g' + ), + DESTINATION_FOLDER + ) } ) }