feat: add font MIME types and fix dfont/ico detection collision

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 12:57:35 +02:00
co-authored by Claude Sonnet 5
parent 2cde4ec035
commit be50f1f076
2 changed files with 44 additions and 0 deletions
+32
View File
@@ -104,3 +104,35 @@ describe('resolveInputFormat — heic/heif alias', () => {
expect(result.valid).toBe(true);
});
});
describe('outputMimeType — fonts', () => {
it('returns the correct MIME type for each font target format', () => {
expect(outputMimeType('ttf')).toBe('font/ttf');
expect(outputMimeType('otf')).toBe('font/otf');
expect(outputMimeType('woff')).toBe('font/woff');
});
});
describe('resolveInputFormat — dfont', () => {
it('confirms file-type alone misidentifies the dfont fixture as ico (documents the bug this fix works around)', async () => {
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample.dfont');
const detected = await detectInputMime(fixturePath);
expect(detected.ext).toBe('ico');
});
it('accepts a real dfont file despite that misidentification', async () => {
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample.dfont');
const result = await resolveInputFormat(fixturePath, 'dfont');
expect(result).toEqual({ mime: 'application/x-dfont', valid: true });
});
it('rejects content starting with the colliding magic bytes that is not a real dfont', async () => {
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample-fake.dfont');
await fs.writeFile(fixturePath, Buffer.from([0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, 0x10]));
const result = await resolveInputFormat(fixturePath, 'dfont');
expect(result).toEqual({ mime: null, valid: false });
await fs.unlink(fixturePath);
});
});