1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Desktop: Fixes #12362: Fixed import of Markdown files that contain links with Windows paths (#12386)

This commit is contained in:
pedr
2025-06-07 08:55:34 -03:00
committed by GitHub
parent a47d7906af
commit 5b42f4f2a2
3 changed files with 13 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
<img src="..\\..\\photo.jpg" />
<a href="..\\..\\sample.txt">Sample</a>

View File

@@ -220,6 +220,14 @@ describe('InteropService_Importer_Md', () => {
expect(note.body).toContain('![malformed link](https://malformed_uri/%E0%A4%A.jpg)');
});
it('should import resources from links with Windows path', async () => {
const note = await importNote(`${supportDir}/test_notes/md/windows_path.html`);
const items = await Note.linkedItems(note.body);
expect(items.length).toBe(2);
expect(items.find(i => i.title === 'sample.txt')).toBeTruthy();
expect(items.find(i => i.title === 'photo.jpg')).toBeTruthy();
});
it.each([
['<a name="525"/>', '<a name="525"></a>'],
['<a name="525" id="test" class="link"/>', '<a name="525" id="test" class="link"></a>'],

View File

@@ -5,7 +5,7 @@ import InteropService_Importer_Base from './InteropService_Importer_Base';
import Folder from '../../models/Folder';
import Note from '../../models/Note';
import { NoteEntity } from '../database/types';
import { basename, filename, rtrimSlashes, fileExtension, dirname } from '../../path-utils';
import { basename, filename, rtrimSlashes, fileExtension, dirname, toForwardSlashes } from '../../path-utils';
import shim from '../../shim';
import markdownUtils from '../../markdownUtils';
import htmlUtils from '../../htmlUtils';
@@ -124,7 +124,8 @@ export default class InteropService_Importer_Md extends InteropService_Importer_
continue;
} else {
// Handle anchor links appropriately
const trimmedLink = this.trimAnchorLink(link);
const linkPosix = toForwardSlashes(link);
const trimmedLink = this.trimAnchorLink(linkPosix);
const attachmentPath = filename(`${dirname(filePath)}/${trimmedLink}`, true);
const pathWithExtension = `${attachmentPath}.${fileExtension(trimmedLink)}`;
const stat = await shim.fsDriver().stat(pathWithExtension);