diff --git a/lib/carrierwave/sanitized_file.rb b/lib/carrierwave/sanitized_file.rb index fd5d3a378..8043e80eb 100644 --- a/lib/carrierwave/sanitized_file.rb +++ b/lib/carrierwave/sanitized_file.rb @@ -2,6 +2,7 @@ require 'active_support/core_ext/string/multibyte' require 'mini_mime' require 'mimemagic' +require 'mimemagic/overlay' module CarrierWave diff --git a/spec/fixtures/resume.docx b/spec/fixtures/resume.docx new file mode 100644 index 000000000..a7308a366 Binary files /dev/null and b/spec/fixtures/resume.docx differ diff --git a/spec/fixtures/slidedeck.pptx b/spec/fixtures/slidedeck.pptx new file mode 100644 index 000000000..9a0b22748 Binary files /dev/null and b/spec/fixtures/slidedeck.pptx differ diff --git a/spec/sanitized_file_spec.rb b/spec/sanitized_file_spec.rb index 70298776d..20fb607f5 100644 --- a/spec/sanitized_file_spec.rb +++ b/spec/sanitized_file_spec.rb @@ -195,6 +195,26 @@ expect(sanitized_file.content_type).to eq("application/msword") end + it "handles Mime::Type of docx" do + file = File.open(file_path('resume.docx')) + + sanitized_file = CarrierWave::SanitizedFile.new(file) + allow(sanitized_file).to receive(:file).and_return(file) + + expect { sanitized_file.content_type }.not_to raise_error + expect(sanitized_file.content_type).to eq("application/vnd.openxmlformats-officedocument.wordprocessingml.document") + end + + it "handles Mime::Type of pptx" do + file = File.open(file_path('slidedeck.pptx')) + + sanitized_file = CarrierWave::SanitizedFile.new(file) + allow(sanitized_file).to receive(:file).and_return(file) + + expect { sanitized_file.content_type }.not_to raise_error + expect(sanitized_file.content_type).to eq("application/vnd.openxmlformats-officedocument.presentationml.presentation") + end + it "reads content type from path if missing" do sanitized_file = CarrierWave::SanitizedFile.new("llama.jpg")