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

don't make default_type global #78

Closed
jonathanong opened this issue Nov 28, 2013 · 6 comments
Closed

don't make default_type global #78

jonathanong opened this issue Nov 28, 2013 · 6 comments

Comments

@jonathanong
Copy link

i'd prefer when a lookup fails, it returns something falsey like false instead of application/octet-stream. i would love to set the default type to something, but since it's global, i'm afraid it'll ruin other modules since this repo is used a lot.

aside from doing a major version bump, how about adding a second "default" option to the methods?

mime.lookup(file, false)

would return a valid mime type or false

@broofa
Copy link
Owner

broofa commented Nov 28, 2013

Old, but relevant Mozilla discussion about default types: https://issues.apache.org/bugzilla/show_bug.cgi?id=13986 (just dropping this here for reference. not expressing any opinion on how it may or may not apply here.)

@broofa
Copy link
Owner

broofa commented Nov 28, 2013

You make a good point about how the 'global' nature of default_type is problematic. Will have to digest this. Could you (in the mean time) just check (mime.lookup('foo') === mime.default_type) for now? I know it's less than ideal. :-/

@jonathanong
Copy link
Author

Yeah not a big deal. Thanks!

@andrewrk
Copy link

mime.lookup('foo') === mime.default_type is not correct and can lead to subtle bugs. What if some other module sets default_type to image/png? Now all my PNGs have a bogus mime type.

There's an easy workaround though, just make the fallback parameter to lookup public instead of private API. E.g. advertise in the README that it's OK to use.

@jons
Copy link

jons commented Jun 4, 2015

when in doubt, do what the standard says, or in this case, do what the most common tools do.

http://linux.die.net/man/1/file
http://linux.die.net/man/5/magic

@broofa
Copy link
Owner

broofa commented Jun 15, 2017

See #139 (plan is to have v2 return null instead of default type.)

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

4 participants