Commit a9dab953 authored by Brett Walker's avatar Brett Walker Committed by Luke Duncalfe

Use ruby-magic gem instead of mimemagic gem

due to licensing issues
parent f31e6437
......@@ -274,7 +274,7 @@ gem 'licensee', '~> 9.14.1'
gem 'charlock_holmes', '~> 0.7.7'
# Detect mime content type from content
gem 'mimemagic', '~> 0.3.2'
gem 'ruby-magic'
# Faster blank
gem 'fast_blank'
......
......@@ -1109,6 +1109,7 @@ GEM
i18n
ruby-fogbugz (0.2.1)
crack (~> 0.4)
ruby-magic (0.2.0)
ruby-prof (1.3.1)
ruby-progressbar (1.11.0)
ruby-saml (1.7.2)
......@@ -1481,7 +1482,6 @@ DEPENDENCIES
marginalia (~> 1.10.0)
memory_profiler (~> 0.9)
method_source (~> 1.0)
mimemagic (~> 0.3.2)
mini_magick (~> 4.10.1)
minitest (~> 5.11.0)
multi_json (~> 1.14.1)
......@@ -1555,6 +1555,7 @@ DEPENDENCIES
rspec_junit_formatter
rspec_profiling (~> 0.0.6)
ruby-fogbugz (~> 0.2.1)
ruby-magic
ruby-prof (~> 1.3.0)
ruby-progressbar (~> 1.10)
ruby_parser (~> 3.15)
......
---
title: Remove direct mimemagic dependency
merge_request: 57387
author:
type: other
# frozen_string_literal: true
require 'magic'
# This wraps calls to a gem which support mime type detection.
# Currently uses `mimemagic`, but that will be replaced shortly.
# We use the `ruby-magic` gem instead of `mimemagic` due to licensing issues
module Gitlab
module Utils
class MimeType
......@@ -9,13 +10,14 @@ module Gitlab
def from_io(io)
return unless io.is_a?(IO) || io.is_a?(StringIO)
MimeMagic.by_magic(io).try(:type)
mime_type = File.magic(io, Magic::MIME_TYPE)
mime_type == 'inode/x-empty' ? nil : mime_type
end
def from_string(string)
return unless string.is_a?(String)
MimeMagic.by_magic(string)
string.type
end
end
end
......
......@@ -24,7 +24,7 @@ RSpec.describe Gitlab::Utils::MimeType do
"rails_sample.png" | "image/png"
"rails_sample.bmp" | "image/bmp"
"rails_sample.tif" | "image/tiff"
"blockquote_fence_before.md" | nil
"blockquote_fence_before.md" | "text/plain"
"csv_empty.csv" | nil
end
......@@ -50,7 +50,7 @@ RSpec.describe Gitlab::Utils::MimeType do
context "input is a string" do
let(:str) { "plain text" }
it { is_expected.to eq(nil) }
it { is_expected.to eq('text/plain') }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment