FEATURE: perform case insensitive lookups

FEATURE: perform case insensitive lookups

This corrects rails/rails#41796

Previously lookup by extension was case sensitive leading to a slight disparity between mime-types implementation and mini-mime

New implementation is slightly more efficient for correctly cased lookups.

diff --git a/lib/mini_mime.rb b/lib/mini_mime.rb
index dc3d829..566a5b1 100644
--- a/lib/mini_mime.rb
+++ b/lib/mini_mime.rb
@@ -56,14 +56,14 @@ module MiniMime
       extension = File.extname(filename)
       return if extension.empty?
       extension = extension[1..-1]
-      extension.downcase!
       lookup_by_extension(extension)
     end
 
     def self.lookup_by_extension(extension)
       LOCK.synchronize do
         @db ||= new
-        @db.lookup_by_extension(extension)
+        @db.lookup_by_extension(extension) ||
+          @db.lookup_by_extension(extension.downcase)
       end
     end
 
diff --git a/test/mini_mime_test.rb b/test/mini_mime_test.rb
index cec80f4..da8aac2 100644
--- a/test/mini_mime_test.rb
+++ b/test/mini_mime_test.rb
@@ -15,8 +15,16 @@ class MiniMimeTest < Minitest::Test
     assert_equal "application/zip", MiniMime.lookup_by_extension("zip").content_type
   end
 
+  def test_mixed_case
+
+    # irb(main):009:0> MIME::Types.type_for("TxT").first.to_s
+    # => "text/plain"
+
+    assert_equal "application/vnd.groove-tool-message", MiniMime.lookup_by_filename("a.GTM").content_type
+    assert_equal "application/zip", MiniMime.lookup_by_extension("ZiP").content_type
+  end
+
   def test_content_type
-    # keep lotus alive cause these files are EVERYWHERE
     assert_equal "application/vnd.lotus-1-2-3", MiniMime.lookup_by_filename("a.123").content_type
     assert_equal "application/x-compressed", MiniMime.lookup_by_filename("a.Z").content_type
     assert_equal "application/vnd.groove-tool-message", MiniMime.lookup_by_filename("a.gtm").content_type
@@ -30,6 +38,7 @@ class MiniMimeTest < Minitest::Test
   def test_binary
     # note this is not strictly correct but .Z is the only
     # upper case extension, being correct here seems overkill
+    # many already rely on case insensitive lookups (which is implemented by mime types)
     assert MiniMime.lookup_by_filename("a.z").binary?
     assert MiniMime.lookup_by_filename("a.Z").binary?
     refute MiniMime.lookup_by_filename("a.txt").binary?

GitHub sha: 63802d1e45cb2b831c34b5d68e364b5ea35c050a