Feature #44385 ยป replace-mini_mime-with-marcel.patch
| Gemfile | ||
|---|---|---|
| 4 | 4 | |
| 5 | 5 |
gem 'rails', '8.1.3.1' |
| 6 | 6 |
gem 'rouge', '~> 5.0' |
| 7 |
gem 'mini_mime', '~> 1.1.0' |
|
| 8 | 7 |
gem "actionpack-xml_parser" |
| 9 | 8 |
gem 'roadie-rails', '~> 3.4.0' |
| 10 | 9 |
gem 'marcel' |
| lib/redmine/mime_type.rb | ||
|---|---|---|
| 46 | 46 |
'image/png' => 'png', |
| 47 | 47 |
'image/tiff' => 'tiff,tif', |
| 48 | 48 |
'image/webp' => 'webp', |
| 49 |
# Not registered with IANA, but matches Marcel's type for .ai |
|
| 50 |
'application/illustrator' => 'ai', |
|
| 51 | 49 |
'application/javascript' => 'js', |
| 52 | 50 |
'application/pdf' => 'pdf', |
| 53 | 51 |
'video/mp4' => 'mp4', |
| ... | ... | |
| 66 | 64 | |
| 67 | 65 |
# returns mime type for name or nil if unknown |
| 68 | 66 |
def self.of(name) |
| 69 |
ext = File.extname(name.to_s)[1..-1] |
|
| 70 |
if ext |
|
| 71 |
ext.downcase! |
|
| 72 |
EXTENSIONS[ext] || MiniMime.lookup_by_extension(ext)&.content_type |
|
| 67 |
ext = File.extname(name.to_s).delete_prefix('.').downcase
|
|
| 68 |
return if ext.empty? |
|
| 69 | ||
| 70 |
EXTENSIONS.fetch(ext) do |
|
| 71 |
type = Marcel::MimeType.for(extension: ext) |
|
| 72 |
# Marcel falls back to application/octet-stream for unknown extensions |
|
| 73 |
type unless type == Marcel::MimeType::BINARY |
|
| 73 | 74 |
end |
| 74 | 75 |
end |
| 75 | 76 | |
| test/unit/lib/redmine/mime_type_test.rb | ||
|---|---|---|
| 87 | 87 |
assert_includes image_types, 'image/webp' |
| 88 | 88 |
end |
| 89 | 89 | |
| 90 |
def test_should_default_to_mime_type_gem
|
|
| 90 |
def test_should_fall_back_to_marcel
|
|
| 91 | 91 |
assert !Redmine::MimeType::EXTENSIONS.key?("zip")
|
| 92 | 92 |
assert_equal "application/zip", Redmine::MimeType.of("file.zip")
|
| 93 | 93 |
end |