Skip to content

Commit

Permalink
Desktop: Resolves #11575: Remove "URI malformed" alert (#11576)
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 authored Jan 9, 2025
1 parent d817ddd commit 83db585
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![malformed link](https://malformed_uri/%E0%A4%A.jpg)
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
});
});
9 changes: 8 additions & 1 deletion packages/lib/services/interop/InteropService_Importer_Md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 83db585

Please sign in to comment.