diff --git a/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts b/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts index 341e43beb..a0ab30c9e 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts @@ -12,6 +12,7 @@ const { clipboard } = require('electron'); const mimeUtils = require('@joplin/lib/mime-utils.js').mime; const md5 = require('md5'); const path = require('path'); +const uri2path = require('file-uri-to-path'); const logger = Logger.create('resourceHandling'); @@ -142,21 +143,21 @@ export async function processPastedHtml(html: string) { if (!mappedResources[imageSrc]) { try { if (imageSrc.startsWith('file')) { - const imageFilePath = path.normalize(unescape(imageSrc).substr(7)); + const imageFilePath = path.normalize(uri2path(imageSrc)); const resourceDirPath = path.normalize(Setting.value('resourceDir')); if (imageFilePath.startsWith(resourceDirPath)) { mappedResources[imageSrc] = imageSrc; } else { const createdResource = await shim.createResourceFromPath(imageFilePath); - mappedResources[imageSrc] = `file://${escape(Resource.fullPath(createdResource))}`; + mappedResources[imageSrc] = `file://${encodeURI(Resource.fullPath(createdResource))}`; } } else { const filePath = `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}`; await shim.fetchBlob(imageSrc, { path: filePath }); const createdResource = await shim.createResourceFromPath(filePath); await shim.fsDriver().remove(filePath); - mappedResources[imageSrc] = `file://${escape(Resource.fullPath(createdResource))}`; + mappedResources[imageSrc] = `file://${encodeURI(Resource.fullPath(createdResource))}`; } } catch (error) { logger.warn(`Error creating a resource for ${imageSrc}.`, error); diff --git a/packages/app-desktop/package-lock.json b/packages/app-desktop/package-lock.json index 5f8a33e52..54a8b1461 100644 --- a/packages/app-desktop/package-lock.json +++ b/packages/app-desktop/package-lock.json @@ -3199,7 +3199,8 @@ }, "ini": { "version": "1.3.5", - "resolved": "", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true, "optional": true }, @@ -3260,7 +3261,8 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "optional": true, "requires": { @@ -3425,7 +3427,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true, "optional": true } @@ -4218,6 +4221,15 @@ "optional": true, "requires": { "file-uri-to-path": "1.0.0" + }, + "dependencies": { + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true, + "optional": true + } } }, "bl": { @@ -6964,11 +6976,9 @@ } }, "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "dev": true, - "optional": true + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-2.0.0.tgz", + "integrity": "sha512-hjPFI8oE/2iQPVe4gbrJ73Pp+Xfub2+WI2LlXDbsaJBwT5wuMh35WNWVYYTpnz895shtwfyutMFLFywpQAFdLg==" }, "filelist": { "version": "1.0.2", @@ -7649,7 +7659,8 @@ }, "ini": { "version": "1.3.5", - "resolved": "", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true, "optional": true }, @@ -7893,7 +7904,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true, "optional": true } @@ -8354,7 +8366,8 @@ }, "y18n": { "version": "3.2.1", - "resolved": "", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", + "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=", "dev": true }, "yargs": { diff --git a/packages/app-desktop/package.json b/packages/app-desktop/package.json index de0bf7933..ad945ea61 100644 --- a/packages/app-desktop/package.json +++ b/packages/app-desktop/package.json @@ -133,6 +133,7 @@ "electron-context-menu": "^0.15.0", "electron-is-dev": "^0.3.0", "electron-window-state": "^4.1.1", + "file-uri-to-path": "^2.0.0", "formatcoords": "^1.1.3", "fs-extra": "^5.0.0", "highlight.js": "^10.2.1",