Skip to content

Commit

Permalink
Merge pull request #2464 from alexpooley/efficient-type-check
Browse files Browse the repository at this point in the history
Skip content type filters where possible.
  • Loading branch information
mshibuya authored Jan 17, 2021
2 parents 79fe010 + 5ce998a commit 39dfdcd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/carrierwave/uploader/content_type_blacklist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ def content_type_blacklist; end
private

def check_content_type_blacklist!(new_file)
return unless content_type_blacklist

content_type = new_file.content_type
if content_type_blacklist && blacklisted_content_type?(content_type)
if blacklisted_content_type?(content_type)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_blacklist_error", content_type: content_type)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/carrierwave/uploader/content_type_whitelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ def content_type_whitelist; end
private

def check_content_type_whitelist!(new_file)
return unless content_type_whitelist

content_type = new_file.content_type
if content_type_whitelist && !whitelisted_content_type?(content_type)
if !whitelisted_content_type?(content_type)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type, allowed_types: Array(content_type_whitelist).join(", "))
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/carrierwave/uploader/extension_blacklist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def extension_blacklist; end
private

def check_extension_blacklist!(new_file)
return unless extension_blacklist

extension = new_file.extension.to_s
if extension_blacklist && blacklisted_extension?(extension)
if blacklisted_extension?(extension)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_blacklist_error", extension: new_file.extension.inspect, prohibited_types: Array(extension_blacklist).join(", "))
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/carrierwave/uploader/extension_whitelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def extension_whitelist; end
private

def check_extension_whitelist!(new_file)
return unless extension_whitelist

extension = new_file.extension.to_s
if extension_whitelist && !whitelisted_extension?(extension)
if !whitelisted_extension?(extension)
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_whitelist_error", extension: new_file.extension.inspect, allowed_types: Array(extension_whitelist).join(", "))
end
end
Expand Down

0 comments on commit 39dfdcd

Please sign in to comment.