Skip to content

Commit 6960c8b

Browse files
authored
Merge pull request #2835 from ehhc/fix_broken_attachments
Strange url-handling reverted + tests modified so that they might fin…
2 parents 950d31a + 7165c45 commit 6960c8b

File tree

2 files changed

+109
-71
lines changed

2 files changed

+109
-71
lines changed

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,7 @@ function migrateAttachments (markdownContent, storagePath, noteKey) {
227227
* @returns {String} postprocessed HTML in which all :storage references are mapped to the actual paths.
228228
*/
229229
function fixLocalURLS (renderedHTML, storagePath) {
230-
/*
231-
A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
232-
233-
- `STORAGE_FOLDER_PLACEHOLDER` will match `:storage`
234-
- `(?:(?:\\\/|%5C)[\\w.]+)+` will match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`
235-
- `(?:\\\/|%5C)[\\w.]+` will either match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564` or `/f939b2c3.jpg`
236-
- `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
237-
*/
238-
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[\\w.]+)+', 'g'), function (match) {
230+
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?"', 'g'), function (match) {
239231
var encodedPathSeparators = new RegExp(mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep), 'g')
240232
return match.replace(encodedPathSeparators, path.sep).replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g'), 'file:///' + path.join(storagePath, DESTINATION_FOLDER))
241233
})
@@ -429,7 +421,14 @@ function replaceNoteKeyWithNewNoteKey (noteContent, oldNoteKey, newNoteKey) {
429421
* @returns {String} Input without the references
430422
*/
431423
function removeStorageAndNoteReferences (input, noteKey) {
432-
return input.replace(new RegExp(mdurl.encode(path.sep), 'g'), path.sep).replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + escapeStringRegexp(path.sep) + noteKey + ')?', 'g'), DESTINATION_FOLDER)
424+
return input.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|])', 'g'), function (match) {
425+
const temp = match
426+
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.sep)
427+
.replace(new RegExp(mdurl.encode(path.posix.sep), 'g'), path.sep)
428+
.replace(new RegExp(escapeStringRegexp(path.win32.sep), 'g'), path.sep)
429+
.replace(new RegExp(escapeStringRegexp(path.posix.sep), 'g'), path.sep)
430+
return temp.replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + escapeStringRegexp(path.sep) + noteKey + ')?', 'g'), DESTINATION_FOLDER)
431+
})
433432
}
434433

435434
/**

0 commit comments

Comments
 (0)