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

mimetype doesn't resolve globs conflict #11

Open
ghost opened this issue Jan 19, 2015 · 1 comment
Open

mimetype doesn't resolve globs conflict #11

ghost opened this issue Jan 19, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 19, 2015

When mime database contains types with same glob patterns, mimetype always pick up the first type and doesn't use magics. It broke this recommendation.

Example database content:

<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-foobin">
    <comment>foo file (binary)</comment> 
    <glob pattern="*.foo"/>
    <magic priority="50">
      <match value="I am binary foo!" type="string" offset="0"/>
    </magic>
  </mime-type>
<mime-type type="text/x-foo">
    <comment>foo file</comment> 
    <glob pattern="*.foo"/>
    <magic priority="50">
      <match value="I am text foo!" type="string" offset="0"/>
    </magic>
  </mime-type>
</mime-info>

Example.foo

I am text foo!

After updating MIME database mimetype should return "text/x-foo":

$ mimetype --database=mime Example.foo
Example.foo: application/x-foobin
$ mimetype --database=mime -a Example.foo
Example.foo: application/x-foobin
Example.foo: text/x-foo
Example.foo: text/plain
$ mimetype --database=mime -D Example.foo
> Data dirs are: mime
> Checking inode type
> Checking globs for basename 'Example.foo'
> Checking for extension '.foo'
Example.foo: application/x-foobin

And if globs disabled:

$ mimetype --database=mime  -M Example.foo
Example.foo: text/x-foo
@majutsushi
Copy link

This is still an issue, I just came across it because the tool incorrectly recognized an OTF font file as an OpenDocument formula template:

$ mimetype Vollkorn-Bold.otf
Vollkorn-Bold.otf: application/vnd.oasis.opendocument.formula-template
$ mimetype -a Vollkorn-Bold.otf
Vollkorn-Bold.otf: application/vnd.oasis.opendocument.formula-template
Vollkorn-Bold.otf: font/otf
Vollkorn-Bold.otf: application/octet-stream
$ mimetype -M Vollkorn-Bold.otf
Vollkorn-Bold.otf: font/otf

According to the spec glob conflicts should be resolved by inspecting the magic data:

If a matching pattern is provided by two or more MIME types, applications SHOULD not rely on one of them. They are instead supposed to use magic data (see below) to detect the actual MIME type. This is for instance required to deal with container formats like Ogg or AVI, that map various video and/or audio-encoded data to one extension.

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