Skip to content

All: Fixes #12362: Fixes resources linked with Windows path not being imported #12386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<img src="..\\..\\photo.jpg" />
<a href="..\\..\\sample.txt">Sample</a>
Original file line number Diff line number Diff line change
Expand Up @@ -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>'],
Expand Down
5 changes: 3 additions & 2 deletions packages/lib/services/interop/InteropService_Importer_Md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down