1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-07 19:30:04 +02:00

Desktop: Resolves #11575: Remove "URI malformed" alert (#11576)

This commit is contained in:
Self Not Found 2025-01-09 15:26:20 +00:00 committed by GitHub
parent d817ddd5c6
commit 83db585c0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1 @@
![malformed link](https://malformed_uri/%E0%A4%A.jpg)

View File

@ -195,4 +195,13 @@ describe('InteropService_Importer_Md', () => {
// The invalid image is imported as-is
expect(resource.title).toBe('invalid-image.jpg');
});
it('should not fail to import file that contains a malformed URI', async () => {
// The first implicit test is that the below call doesn't throw due to the malformed URI
const note = await importNote(`${supportDir}/test_notes/md/sample-malformed-uri.md`);
const itemIds = Note.linkedItemIds(note.body);
expect(itemIds.length).toBe(0);
// The malformed link is imported as-is
expect(note.body).toContain('![malformed link](https://malformed_uri/%E0%A4%A.jpg)');
});
});

View File

@ -110,11 +110,18 @@ export default class InteropService_Importer_Md extends InteropService_Importer_
const htmlLinks = htmlUtils.extractFileUrls(md);
const fileLinks = unique(markdownLinks.concat(htmlLinks));
for (const encodedLink of fileLinks) {
const link = decodeURI(encodedLink);
let link = '';
try {
link = decodeURI(encodedLink);
} catch (error) {
// If the URI cannot be decoded, leave it as it is.
continue;
}
if (isDataUrl(link)) {
// Just leave it as it is. We could potentially import
// it as a resource but for now that's good enough.
continue;
} else {
// Handle anchor links appropriately
const trimmedLink = this.trimAnchorLink(link);