Skip to content

Commit

Permalink
Add public interface alternative to blacklist
Browse files Browse the repository at this point in the history
Add public interface alternative to blacklist
so users who prefer not to use that terminology
can use blocklist in their own uploader code.

To make this change minimally intrusive as a start,
the default blacklist methods now call the blocklist methods
so either method can be overridden and it will work as expected
while maintaining backwards compatibility.

https://developers.google.com/style/word-list#blacklist
rubocop/rubocop#6464
  • Loading branch information
grantbdev authored and joemsak committed Mar 27, 2021
1 parent db1ab22 commit 9305f83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/carrierwave/uploader/content_type_blacklist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ module ContentTypeBlacklist
# [/(text|application)\/json/]
# end
#
def content_type_blacklist; end
def content_type_blacklist
content_type_blocklist
end

def content_type_blocklist; end

private

Expand Down
6 changes: 5 additions & 1 deletion lib/carrierwave/uploader/extension_blacklist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ module ExtensionBlacklist
# end
#

def extension_blacklist; end
def extension_blacklist
extension_blocklist
end

def extension_blocklist; end

private

Expand Down
6 changes: 6 additions & 0 deletions spec/uploader/content_type_blacklist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
expect { uploader.cache!(ruby_file) }.to raise_error(CarrierWave::IntegrityError)
end

it "raises an integrity error if the file has a blocklisted content type" do
allow(uploader).to receive(:content_type_blocklist).and_return(['image/png'])

expect { uploader.cache!(ruby_file) }.to raise_error(CarrierWave::IntegrityError)
end

it "accepts content types as regular expressions" do
allow(uploader).to receive(:content_type_blacklist).and_return([/image\//])

Expand Down
2 changes: 1 addition & 1 deletion spec/uploader/extension_blacklist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
before { allow(CarrierWave).to receive(:generate_cache_id).and_return(cache_id) }

describe '#cache!' do
before { allow(uploader).to receive(:extension_blacklist).and_return(extension_blacklist) }
before { allow(uploader).to receive(:extension_blocklist).and_return(extension_blacklist) }

context "when there are no blacklisted extensions" do
let(:extension_blacklist) { nil }
Expand Down

0 comments on commit 9305f83

Please sign in to comment.