Fix file:// URI handling in getBinaryContentsAsync()

This commit is contained in:
Dan Stillman 2023-11-10 15:58:53 -05:00
parent 8239d04d5e
commit f1373652e6
2 changed files with 12 additions and 1 deletions

View file

@ -311,7 +311,7 @@ Zotero.File = new function(){
if (source instanceof Components.interfaces.nsIFile) {
source = source.path;
}
else if (source.startsWith('^file:')) {
else if (source.startsWith('file:')) {
source = OS.Path.fromFileURI(source);
}
var options = {};

View file

@ -70,6 +70,17 @@ describe("Zotero.File", function () {
}
});
it("should take a file:// URI", async function () {
var file = OS.Path.join(getTestDataDirectory().path, "test.png");
var uri = PathUtils.toFileURI(file);
var contents = await Zotero.File.getBinaryContentsAsync(uri);
assert.isAbove(contents.length, magicPNG.length);
for (let i = 0; i < magicPNG.length; i++) {
assert.equal(magicPNG[i], contents.charCodeAt(i));
}
});
it("should respect maxLength", function* () {
var contents = yield Zotero.File.getBinaryContentsAsync(
OS.Path.join(getTestDataDirectory().path, "test.png"),