discourse / mini_mime

minimal mime type library
MIT License
95 stars 34 forks source link

Wrong lookup_by_content_type extension? #8

Closed toshimaru closed 7 years ago

toshimaru commented 7 years ago

According to README, it says:

MiniMime.lookup_by_content_type("text/plain").extension
# => "txt"

But I tried it on my irb, it returns different string.

$ irb
> require 'mini_mime'
=> true

> MiniMime.lookup_by_filename("a.txt")
=> #<MiniMime::Info:0x007fa692a31cc8 @extension="txt", @content_type="text/plain", @encoding="quoted-printable">

> MiniMime.lookup_by_content_type("text/plain")
=> #<MiniMime::Info:0x007fa69383d178 @extension="c", @content_type="text/plain", @encoding="quoted-printable">

> MiniMime.lookup_by_content_type("text/plain").extension
=> "c"

I expected "txt" returned, but it doesn't.

SamSaffron commented 7 years ago

I agree this is a glitch, but there is no obvious solution

irb(main):007:0> MIME::Types.type_for("a.txt")[0].extensions[0]
=> "txt"
irb(main):008:0> MIME::Types.type_for("a.c")[0].extensions[0]
=> "txt"

Will fix it so we always at least return the first extension correctly

toshimaru commented 7 years ago

:cool::+1: