-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove ruby-filemagic dependency and refactor/redesign content type white/blacklisting feature #1816
Remove ruby-filemagic dependency and refactor/redesign content type white/blacklisting feature #1816
Conversation
58fb7a5
to
784b485
Compare
@@ -3,19 +3,27 @@ | |||
describe CarrierWave::Uploader do | |||
|
|||
it "should keep callbacks on different classes isolated" do | |||
default_before_callbacks = [ | |||
:check_whitelist!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth changing check_whitelist!
to check_extension_whitelist!
and similar. Happy to do it as a separate PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually did it already
mehlah/carrierwave@remove-magicmime...mehlah:refactor-extensions-white/blacklist#diff-2bca1d8b1d06f3d29a6553468c7b940fR7
I'll PR the refactor for better consistency as soon as this is accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
See carrierwaveuploader#1813 for background.
Before this, CarrierWave was relying on mime-types or ruby-filemagic gems to get/set the content type of a file in an inconsistent way. After making mime-types a runtime dependency for CW, `CarrierWave::MimeTypes` has been dropped (carrierwaveuploader#1813 for details), and `CarrierWave::MagicMimeTypes` as well. White/blacklisting content types feature (introduced by carrierwaveuploader#1596) was relying only on ruby-filemagic to read the content type of a file. It was optional and required mixing a module to the uploader. This commit removes this dependency by using the already available content type (thanks to `Mime::Types`). This let us drop any dependency on ruby-filemagic in CarrierWave. It makes JRuby support better as ruby-filemagic is unsupported on JRuby due to the C extension.
This is more consistent with the current way of white/blacklisting extensions.
784b485
to
fe98ee3
Compare
I screwed up 6df8c83 after a rebase (made the build red https://travis-ci.org/carrierwaveuploader/carrierwave/jobs/99844432). Now fixed ;) |
Refactor content type filtering and remove ruby-filemagic
This PR removes
CarrierWave::MagicMimeTypes
processor module at d6fa112 (see #1813 for background).As discussed with @thomasfedb (#1813 (comment)), it also remove the dependency on
ruby-filemagic
in white/blacklist content types (b5bec3d).Background: Before this, CarrierWave was relying on mime-types or ruby-filemagic
gems to get/set the content type of a file in an inconsistent way.
After making mime-types a runtime dependency for CW,
CarrierWave::MimeTypes
has been dropped, andCarrierWave::MagicMimeTypes
as well with this.White/blacklisting content types feature (introduced by #1596) was relying only on ruby-filemagic to read the content type of a file.
It was optional and required mixing a module to the uploader.
This PR removes this dependency by using the already available content type (thanks to
Mime::Types
).This let us drop any dependency on ruby-filemagic in CarrierWave.
It makes JRuby support better as ruby-filemagic is unsupported on JRuby due to the C extension.
I also made some refactors, renamed methods like
whitelist_mime_type_pattern
tocontent_type_whitelist
, cleaned up specs and docs.The module doesn't need to be optional now, so it's included by default (like
ExtensionWhitelist
andExtensionBlacklist
)To keep it consistent with the current way of white/blacklisting extensions,
content_type_whitelist
now accepts an array of strings or regexps to white/blacklist content types. I can move 07c80cb to a separate PR if you prefer.