From 42572efca9314a6770c0d4898bcad41079c6af94 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 25 May 2023 18:45:48 +0300 Subject: [PATCH] Fix error when adding link attachment with unparseable URL https://forums.zotero.org/discussion/105158/zotero-7-beta-attach-link-to-uri-logosres-does-not-work-any-longer --- chrome/content/zotero/xpcom/attachments.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 70c6c29a9e..fe4b38f67a 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -2885,10 +2885,18 @@ Zotero.Attachments = new function(){ } - this._getExtensionFromURL = function(url, contentType) { - var nsIURL = Services.io.newURI(url) - .QueryInterface(Ci.nsIURL); - return Zotero.MIME.getPrimaryExtension(contentType, nsIURL.fileExtension); + this._getExtensionFromURL = function (url, contentType) { + let fileExtension; + try { + let nsIURL = Services.io.newURI(url) + .QueryInterface(Ci.nsIURL); + fileExtension = nsIURL.fileExtension; + } + catch (e) { + // The URI is not a URL + fileExtension = ''; + } + return Zotero.MIME.getPrimaryExtension(contentType, fileExtension); }