Skip to content

Commit

Permalink
[Validator] Fix issue with all_available_marcel_content_types mutatin…
Browse files Browse the repository at this point in the history
…g Marcel::TYPE_EXTS (#356)
  • Loading branch information
Mth0158 committed Jan 31, 2025
1 parent 9466e97 commit 84f0596
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/active_storage_validations/content_type_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ def invalid_content_type?(content_type)
raise ArgumentError, "'image/jpg' is not a valid content type, you should use 'image/jpeg' instead"
end

all_available_marcel_content_types.keys.exclude?(content_type.to_s)
all_available_marcel_content_types.exclude?(content_type.to_s)
end

def all_available_marcel_content_types
@all_available_marcel_content_types ||= Marcel::MAGIC.map {|dd| dd.first }
.each_with_object(Marcel::TYPE_EXTS) { |(k,v), h| h[k] = v unless h.key?(k) }
@all_available_marcel_content_types ||= Marcel::TYPE_EXTS
.keys
.push(*Marcel::MAGIC.map(&:first))
.tap(&:uniq!)
end

def invalid_extension?(content_type)
Expand Down

0 comments on commit 84f0596

Please sign in to comment.