Project

General

Profile

Patch #29359 » mime_type.rb.patch

Pavel Rosický, 2018-08-10 21:42

View differences:

mime_type.rb (working copy)
15 15
# along with this program; if not, write to the Free Software
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 17

  
18
require 'mime/types'
19

  
20 18
module Redmine
21 19
  module MimeType
22 20

  
......
62 60
    # returns mime type for name or nil if unknown
63 61
    def self.of(name)
64 62
      return nil unless name.present?
65
      if m = name.to_s.match(/(^|\.)([^\.]+)$/)
66
        extension = m[2].downcase
67
        @known_types ||= Hash.new do |h, ext|
68
          type = EXTENSIONS[ext]
69
          type ||= MIME::Types.type_for(ext).first.to_s.presence
70
          h[ext] = type
63
      ext = File.extname(name)[1..-1].to_s
64
      ext.downcase!
65
      EXTENSIONS[ext] ||
66
        MiniMime::Db::LOCK.synchronize do
67
          db = MiniMime::Db.instance_variable_get(:@db)
68
          db ||= MiniMime::Db.instance_variable_set(:@db, MiniMime::Db.new)
69
          lookup = db.lookup_by_extension(ext)
70
          lookup.content_type if lookup
71 71
        end
72
        @known_types[extension]
73
      end
74 72
    end
75 73

  
76 74
    # Returns the css class associated to
77 75
    # the mime type of name
78 76
    def self.css_class_of(name)
79 77
      mime = of(name)
80
      mime && mime.gsub('/', '-')
78
      mime && mime.tr('/', '-')
81 79
    end
82 80

  
83 81
    def self.main_mimetype_of(name)
(2-2/7)