From ef3ac6e4a7f77add479f7c30c7470acb41c73def Mon Sep 17 00:00:00 2001 From: ThibG Date: Sun, 24 Jun 2018 13:33:06 +0200 Subject: [PATCH] Fix jpeg files sometimes being returned with a .jpe extension (#7881) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While this isn't exactly *wrong*, files uploaded with a “.jpe” extension will keep that extension, which will often cause them to be served with an incorrect mimetype. --- app/models/concerns/attachmentable.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index db63c3ecac..44bdfa39a5 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -42,8 +42,9 @@ module Attachmentable extensions_for_mime_type = mime_type.empty? ? [] : mime_type.first.extensions original_extension = Paperclip::Interpolations.extension(attachment, :original) proper_extension = extensions_for_mime_type.first.to_s - proper_extension = 'jpeg' if proper_extension == 'jpe' + extension = extensions_for_mime_type.include?(original_extension) ? original_extension : proper_extension + extension = 'jpeg' if extension == 'jpe' - extensions_for_mime_type.include?(original_extension) ? original_extension : proper_extension + extension end end