mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixes #4916: Ensure that image paths that contain spaces are pasted correctly in the Rich Text editor
This commit is contained in:
parent
ebf92605ae
commit
4ea21e0c32
@ -142,21 +142,21 @@ export async function processPastedHtml(html: string) {
|
||||
if (!mappedResources[imageSrc]) {
|
||||
try {
|
||||
if (imageSrc.startsWith('file')) {
|
||||
const imageFilePath = path.normalize(imageSrc.substr(7));
|
||||
const imageFilePath = path.normalize(unescape(imageSrc).substr(7));
|
||||
const resourceDirPath = path.normalize(Setting.value('resourceDir'));
|
||||
|
||||
if (imageFilePath.startsWith(resourceDirPath)) {
|
||||
mappedResources[imageSrc] = imageSrc;
|
||||
} else {
|
||||
const createdResource = await shim.createResourceFromPath(imageFilePath);
|
||||
mappedResources[imageSrc] = `file://${Resource.fullPath(createdResource)}`;
|
||||
mappedResources[imageSrc] = `file://${escape(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://${Resource.fullPath(createdResource)}`;
|
||||
mappedResources[imageSrc] = `file://${escape(Resource.fullPath(createdResource))}`;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(`Error creating a resource for ${imageSrc}.`, error);
|
||||
|
@ -66,6 +66,11 @@ class HtmlUtils {
|
||||
});
|
||||
}
|
||||
|
||||
// Note that the URLs provided by this function are URL-encoded, which is
|
||||
// usually what you want for web URLs. But if they are file:// URLs and the
|
||||
// file path is going to be used, it will need to be unescaped first. The
|
||||
// transformed SRC, must also be escaped before being sent back to this
|
||||
// function.
|
||||
public processImageTags(html: string, callback: Function) {
|
||||
if (!html) return '';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user