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

Replace mime-types gem with mini_mime #2292

Merged
merged 4 commits into from Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
* Replace mime-types dependency with mini_mime(@bradleypriest [#2292](https://github.com/carrierwaveuploader/carrierwave/pull/2292))

## 1.3.1 - 2018-12-29
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion carrierwave.gemspec
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|

s.add_dependency "activesupport", ">= 5.0.0"
s.add_dependency "activemodel", ">= 5.0.0"
s.add_dependency "mime-types", ">= 1.16"
s.add_dependency "mini_mime", ">= 0.1.3"
s.add_dependency "image_processing", "~> 1.1"
if RUBY_ENGINE == 'jruby'
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/processing/mini_magick.rb
Expand Up @@ -306,7 +306,7 @@ def minimagick!(block = nil)

if File.extname(result.path) != File.extname(current_path)
move_to = current_path.chomp(File.extname(current_path)) + File.extname(result.path)
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
file.content_type = ::MiniMime.lookup_by_filename(move_to).content_type
file.move_to(move_to, permissions, directory_permissions)
end
rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/processing/rmagick.rb
Expand Up @@ -363,7 +363,7 @@ def manipulate!(options={}, &block)
if options[:format] || @format
frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
move_to = current_path.chomp(File.extname(current_path)) + ".#{options[:format] || @format}"
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
file.content_type = ::MiniMime.lookup_by_filename(move_to).content_type
file.move_to(move_to, permissions, directory_permissions)
else
frames.write(current_path, &write_block)
Expand Down
11 changes: 3 additions & 8 deletions lib/carrierwave/sanitized_file.rb
@@ -1,12 +1,6 @@
require 'pathname'
require 'active_support/core_ext/string/multibyte'

begin
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
require 'mime/types'
end
require 'mini_mime'

module CarrierWave

Expand Down Expand Up @@ -266,7 +260,8 @@ def content_type
if @file.respond_to?(:content_type) and @file.content_type
@content_type = @file.content_type.to_s.chomp
elsif path
@content_type = ::MIME::Types.type_for(path).first.to_s
mime_type = ::MiniMime.lookup_by_filename(path)
@content_type = (mime_type && mime_type.content_type).to_s
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/carrierwave/uploader/download.rb
Expand Up @@ -18,9 +18,9 @@ def initialize(uri, remote_headers = {})

def original_filename
filename = filename_from_header || filename_from_uri
mime_type = MIME::Types[file.content_type].first
mime_type = MiniMime.lookup_by_content_type(file.content_type)
unless File.extname(filename).present? || mime_type.blank?
filename = "#{filename}.#{mime_type.extensions.first}"
filename = "#{filename}.#{mime_type.extension}"
end
filename
end
Expand Down
9 changes: 1 addition & 8 deletions spec/sanitized_file_spec.rb
@@ -1,12 +1,5 @@
require 'spec_helper'

begin
# Use mime/types/columnar if available, for reduced memory usage
require 'mime/types/columnar'
rescue LoadError
require 'mime/types'
end

describe CarrierWave::SanitizedFile do
before do
FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))
Expand Down Expand Up @@ -237,7 +230,7 @@

it "handles Mime::Type object" do
file = File.open(file_path('sponsored.doc'))
allow(file).to receive(:content_type).and_return(MIME::Type.new("application/msword"))

sanitized_file = CarrierWave::SanitizedFile.new(file)
allow(sanitized_file).to receive(:file).and_return(file)

Expand Down