Fix regression: download() fails for non-http URLs (#2497)
This fixes compatiblity with some addons that use Zotero.File.download to extract files from their XPI bundle.
This commit is contained in:
parent
776769f480
commit
56321a7a6d
3 changed files with 12 additions and 2 deletions
|
@ -448,10 +448,11 @@ Zotero.File = new function(){
|
|||
|
||||
this.download = async function (uri, path) {
|
||||
var uriStr = uri.spec || uri;
|
||||
const isHTTP = uriStr.startsWith('http');
|
||||
|
||||
Zotero.debug(`Saving ${uriStr} to ${path.pathQueryRef || path}`);
|
||||
|
||||
if (Zotero.HTTP.browserIsOffline()) {
|
||||
if (isHTTP && Zotero.HTTP.browserIsOffline()) {
|
||||
let msg = `Download failed: ${Zotero.appName} is currently offline`;
|
||||
Zotero.debug(msg, 2);
|
||||
throw new Error(msg);
|
||||
|
@ -488,7 +489,8 @@ Zotero.File = new function(){
|
|||
deferred.reject(new Error(msg));
|
||||
return;
|
||||
}
|
||||
if (responseStatus != 200) {
|
||||
|
||||
if (isHTTP && responseStatus != 200) {
|
||||
let msg = `Download failed with response code ${responseStatus}`;
|
||||
Zotero.logError(msg);
|
||||
deferred.reject(new Error(msg));
|
||||
|
|
BIN
test/tests/data/fake.xpi
Normal file
BIN
test/tests/data/fake.xpi
Normal file
Binary file not shown.
|
@ -525,5 +525,13 @@ describe("Zotero.File", function () {
|
|||
assert.equal(fileSize, 1024 * 1024 * sizeInMB);
|
||||
}
|
||||
});
|
||||
|
||||
it("should extract a file from xpi", async function () {
|
||||
const url = `jar:file://${getTestDataDirectory().path}/fake.xpi!/test.txt`;
|
||||
const path = OS.Path.join(Zotero.getTempDirectory().path, 'xpi-extracted.txt');
|
||||
await Zotero.File.download(url, path);
|
||||
const contents = await Zotero.File.getContentsAsync(path);
|
||||
assert.equal(contents, 'Hello Zotero\n');
|
||||
});
|
||||
});
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue