class MiniPaperclip::Validators::MediaTypeSpoofValidator

Public Instance Methods

normalize(content_type) click to toggle source
# File lib/mini_paperclip/validators/media_type_spoof_validator.rb, line 15
def normalize(content_type)
  case content_type
  when "image/jpg"
    "image/jpeg"
  else
    content_type
  end
end
validate_each(record, attribute, attachment) click to toggle source
# File lib/mini_paperclip/validators/media_type_spoof_validator.rb, line 6
def validate_each(record, attribute, attachment)
  return unless attachment.meta_content_type

  attachment_content_type = record.read_attribute_for_validation("#{attribute}_content_type")
  unless normalize(attachment.meta_content_type) == normalize(attachment_content_type)
    record.errors.add(attribute, :spoofed_media_type)
  end
end