Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font mimetypes are outdated #164

Open
bjd183 opened this issue Oct 12, 2023 · 4 comments
Open

Font mimetypes are outdated #164

bjd183 opened this issue Oct 12, 2023 · 4 comments

Comments

@bjd183
Copy link

bjd183 commented Oct 12, 2023

RFC8081 (2017) deprecated e.g. application/font-sfnt in favor of font/sfnt.

From the RFC: Deprecated Alias: The existing registration "application/font-sfnt" is deprecated in favor of "font/sfnt".

Some browsers (i.e. Chrome) issue console warnings and refuse to apply the referenced stylesheet <link rel="stylesheet" href="my.url">

Refused to apply style from 'my.url' because its MIME type ('application/font-sfnt') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

@bjd183
Copy link
Author

bjd183 commented Oct 12, 2023

Font mimetypes should be updated to reflect this change. Current workaround is to subclass font types, use add_type, and overwrite filetype.types.FONT with a new tuple to ensure correct behavior of is_font().

@bjd183
Copy link
Author

bjd183 commented Oct 12, 2023

It is not actually possible to subclass because #165

@bjd183
Copy link
Author

bjd183 commented Oct 12, 2023

Workaround for the workaround:

import re

for instance in filetype.font_matchers:
    match = re.match(r'^application/font-(\w+)$', instance.mime)
    suffix = match.group(1)
    instance.__class__.mime = property(lambda self: f'font/{suffix}')

@bjd183
Copy link
Author

bjd183 commented Oct 12, 2023

Another option is to use sys.modules['filetype.types']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant