Fix content type detection for JSON files.
This commit is contained in:
parent
bbaa006765
commit
5e5ee9643a
|
@ -315,7 +315,7 @@ module CarrierWave
|
|||
|
||||
if type.nil?
|
||||
type = Marcel::Magic.by_path(path).try(:type)
|
||||
type = 'invalid/invalid' unless type.nil? || type.start_with?('text/')
|
||||
type = 'invalid/invalid' unless type.nil? || type.start_with?('text/') || type.start_with?('application/json')
|
||||
end
|
||||
|
||||
type
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"bork": "bork"
|
||||
}
|
|
@ -264,6 +264,16 @@ describe CarrierWave::SanitizedFile do
|
|||
expect(sanitized_file.content_type).to eq 'text/plain'
|
||||
end
|
||||
|
||||
it "returns valid content type on JSON file (which is a text file in disguise)" do
|
||||
file = File.open(file_path('bork.json'))
|
||||
|
||||
sanitized_file = CarrierWave::SanitizedFile.new(file)
|
||||
|
||||
expect { sanitized_file.content_type }.not_to raise_error
|
||||
|
||||
expect(sanitized_file.content_type).to eq 'application/json'
|
||||
end
|
||||
|
||||
it "returns missing content type with unknown extension" do
|
||||
file = File.open(file_path('bork.ABCDE'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue