Skip to content

Commit 4e30d4b

Browse files
daiyamRokt33r
authored andcommitted
fix URLs by using the correct path separator ('/' for an url and not path.sep)
1 parent 8505616 commit 4e30d4b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ function migrateAttachments (markdownContent, storagePath, noteKey) {
241241
* @returns {String} postprocessed HTML in which all :storage references are mapped to the actual paths.
242242
*/
243243
function fixLocalURLS (renderedHTML, storagePath) {
244+
const encodedWin32SeparatorRegex = /%5C/g
245+
const storageRegex = new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g')
246+
const storageUrl = 'file:///' + path.join(storagePath, DESTINATION_FOLDER).replace(/\\/g, '/')
247+
244248
/*
245249
A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
246250
@@ -250,8 +254,7 @@ function fixLocalURLS (renderedHTML, storagePath) {
250254
- `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
251255
*/
252256
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[-.\\w]+)+', 'g'), function (match) {
253-
var encodedPathSeparators = new RegExp(mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep), 'g')
254-
return match.replace(encodedPathSeparators, path.sep).replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g'), 'file:///' + path.join(storagePath, DESTINATION_FOLDER))
257+
return match.replace(encodedWin32SeparatorRegex, '/').replace(storageRegex, storageUrl)
255258
})
256259
}
257260

tests/dataApi/attachmentManagement.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,21 @@ it('should replace the all ":storage" path with the actual storage path', functi
304304
' <body data-theme="default">\n' +
305305
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
306306
' <p data-line="2">\n' +
307-
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
307+
' <img src="file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
308308
' </p>\n' +
309309
' <p data-line="4">\n' +
310-
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
310+
' <a href="file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
311311
' </p>\n' +
312312
' <p data-line="6">\n' +
313-
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
313+
' <img src="file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
314314
' </p>\n' +
315315
' <pre class="fence" data-line="8">\n' +
316316
' <span class="filename"></span>\n' +
317-
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'f939b2c3.jpg</div>\n' +
317+
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + 'f939b2c3.jpg</div>\n' +
318318
' </pre>\n' +
319319
' <pre class="fence" data-line="10">\n' +
320320
' <span class="filename"></span>\n' +
321-
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'f939b2c3.jpg</div>\n' +
321+
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + 'f939b2c3.jpg</div>\n' +
322322
' </pre>\n' +
323323
' </body>\n' +
324324
'</html>'
@@ -353,10 +353,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
353353
' <body data-theme="default">\n' +
354354
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
355355
' <p data-line="2">\n' +
356-
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
356+
' <img src="file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
357357
' </p>\n' +
358358
' <p data-line="4">\n' +
359-
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
359+
' <a href="file:///' + storagePath + '/' + storageFolder + '/' + noteKey + '/' + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
360360
' </p>\n' +
361361
' </body>\n' +
362362
'</html>'

0 commit comments

Comments
 (0)