Get binary contents in Zotero.File.getSample()

And fix magic numbers for content-type sniffing, which wrongly used the
Unicode replacement character (which likely just meant we were falling
back to file-extension-based detection)
This commit is contained in:
Dan Stillman 2022-06-17 18:24:44 -04:00
parent 13adfd131c
commit 2b41b0127c
3 changed files with 27 additions and 7 deletions

22
test/tests/mimeTest.js Normal file
View file

@ -0,0 +1,22 @@
describe("Zotero.MIME", function () {
describe("#sniffForMIMEType()", function () {
async function test(filename, expectedType) {
var path = OS.Path.join(getTestDataDirectory().path, filename);
var sample = await Zotero.File.getSample(path);
var type = Zotero.MIME.sniffForMIMEType(sample);
assert.equal(type, expectedType);
}
it("should detect PNG", async function () {
await test('test.png', 'image/png');
});
it("should detect JPEG", async function () {
await test('test.jpg', 'image/jpeg');
});
it("should detect SQLite database", async function () {
await test('dev@zotero.org@www.mendeley.com.sqlite', 'application/x-sqlite3');
});
});
});