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

Remove ruby-filemagic dependency and refactor/redesign content type white/blacklisting feature #1816

Merged
merged 4 commits into from
Jan 2, 2016

Conversation

mehlah
Copy link
Member

@mehlah mehlah commented Jan 2, 2016

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, and CarrierWave::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 to content_type_whitelist, cleaned up specs and docs.
The module doesn't need to be optional now, so it's included by default (like ExtensionWhitelist and ExtensionBlacklist)

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.

@mehlah mehlah changed the title Remove magicmime Remove ruby-filemagic dependency and refactor content type white/blacklisting feature Jan 2, 2016
@mehlah mehlah changed the title Remove ruby-filemagic dependency and refactor content type white/blacklisting feature Remove ruby-filemagic dependency and refactor/redesign content type white/blacklisting feature Jan 2, 2016
@mehlah mehlah force-pushed the remove-magicmime branch 2 times, most recently from 58fb7a5 to 784b485 Compare January 2, 2016 17:22
@@ -3,19 +3,27 @@
describe CarrierWave::Uploader do

it "should keep callbacks on different classes isolated" do
default_before_callbacks = [
:check_whitelist!,
Copy link
Contributor

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.

Copy link
Member Author

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 :bowtie:
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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Mehdi Lahmam added 4 commits January 2, 2016 18:56
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.
@mehlah
Copy link
Member Author

mehlah commented Jan 2, 2016

I screwed up 6df8c83 after a rebase (made the build red https://travis-ci.org/carrierwaveuploader/carrierwave/jobs/99844432). Now fixed ;)

thomasfedb added a commit that referenced this pull request Jan 2, 2016
Refactor content type filtering and remove ruby-filemagic
@thomasfedb thomasfedb merged commit e046ad8 into carrierwaveuploader:master Jan 2, 2016
@mehlah mehlah deleted the remove-magicmime branch January 2, 2016 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants