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
This commit is contained in:
Abe Jellinek 2023-05-25 18:45:48 +03:00
parent a4c3f5267b
commit 42572efca9

View file

@ -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);
}