Skip to content

Commit 3f80967

Browse files
authored
Merge pull request #2551 from pjmartorell/fix/replace-mimemagic-with-marcel
Replace mimemagic with marcel gem
2 parents 0411ae1 + 3cefc38 commit 3f80967

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

carrierwave.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
2525
s.add_dependency "activemodel", ">= 5.0.0"
2626
s.add_dependency "mini_mime", ">= 0.1.3"
2727
s.add_dependency "image_processing", "~> 1.1"
28-
s.add_dependency "mimemagic", ">= 0.3.0"
28+
s.add_dependency "marcel", "~> 1.0.0"
2929
s.add_dependency "addressable", "~> 2.6"
3030
s.add_dependency "ssrf_filter", "~> 1.0"
3131
if RUBY_ENGINE == 'jruby'

lib/carrierwave/sanitized_file.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
require 'pathname'
22
require 'active_support/core_ext/string/multibyte'
33
require 'mini_mime'
4-
require 'mimemagic'
5-
require 'mimemagic/overlay'
4+
require 'marcel'
65

76
module CarrierWave
87

@@ -262,7 +261,7 @@ def to_file
262261
def content_type
263262
@content_type ||=
264263
existing_content_type ||
265-
mime_magic_content_type ||
264+
marcel_magic_content_type ||
266265
mini_mime_content_type
267266
end
268267

@@ -329,14 +328,14 @@ def existing_content_type
329328
end
330329
end
331330

332-
def mime_magic_content_type
331+
def marcel_magic_content_type
333332
if path
334333
type = File.open(path) do |file|
335-
MimeMagic.by_magic(file).try(:type)
334+
Marcel::Magic.by_magic(file).try(:type)
336335
end
337336

338337
if type.nil?
339-
type = ::MiniMime.lookup_by_filename(path).try(:content_type)
338+
type = Marcel::Magic.by_path(file).try(:type)
340339
type = 'invalid/invalid' unless type.nil? || type.start_with?('text/')
341340
end
342341

spec/sanitized_file_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@
378378
expect(sanitized_file.content_type).to eq("application/octet-stream")
379379
end
380380

381-
it "should detect content type correctly using MagicMime when content_type is not set" do
381+
it "should detect content type correctly using Marcel when content_type is not set" do
382382
sanitized_file.content_type = nil
383383
sanitized_file.move_to(file_path("new_dir","gurr.png"))
384384

0 commit comments

Comments
 (0)