File tree Expand file tree Collapse file tree 3 files changed +28
-17
lines changed Expand file tree Collapse file tree 3 files changed +28
-17
lines changed Original file line number Diff line number Diff line change @@ -307,7 +307,7 @@ def sanitize(name)
307
307
def declared_content_type
308
308
@declared_content_type ||
309
309
if @file . respond_to? ( :content_type ) && @file . content_type
310
- @file . content_type . to_s . chomp
310
+ Marcel :: MimeType . for ( declared_type : @file . content_type . to_s . chomp )
311
311
end
312
312
end
313
313
Original file line number Diff line number Diff line change 306
306
307
307
expect { sanitized_file . content_type } . not_to raise_error
308
308
end
309
+
310
+ it "uses the first one when multiple mime types are given using a semicolon" do
311
+ file = File . open ( file_path ( "bork.txt" ) )
312
+ allow ( file ) . to receive ( :content_type ) { 'image/png; text/html' }
313
+
314
+ sanitized_file = CarrierWave ::SanitizedFile . new ( file )
315
+
316
+ expect ( sanitized_file . content_type ) . to eq ( "image/png" )
317
+ end
318
+
319
+ it "uses the first one when multiple mime types are given using a comma" do
320
+ file = File . open ( file_path ( "bork.txt" ) )
321
+ allow ( file ) . to receive ( :content_type ) { 'image/png, text/html' }
322
+
323
+ sanitized_file = CarrierWave ::SanitizedFile . new ( file )
324
+
325
+ expect ( sanitized_file . content_type ) . to eq ( "image/png" )
326
+ end
327
+
328
+ it "drops content type parameters" do
329
+ file = File . open ( file_path ( "bork.txt" ) )
330
+ allow ( file ) . to receive ( :content_type ) { 'text/html; charset=utf-8' }
331
+
332
+ sanitized_file = CarrierWave ::SanitizedFile . new ( file )
333
+
334
+ expect ( sanitized_file . content_type ) . to eq ( "text/html" )
335
+ end
309
336
end
310
337
311
338
describe "#content_type=" do
Original file line number Diff line number Diff line change 87
87
expect { uploader . cache! ( bork_file ) } . to raise_error ( CarrierWave ::IntegrityError )
88
88
end
89
89
end
90
-
91
- context "when the allowlist contains charset" do
92
- before do
93
- allow ( uploader ) . to receive ( :content_type_allowlist ) . and_return ( %r{text/plain;\s *charset=utf-8} )
94
- end
95
-
96
- it "accepts the content with allowed charset" do
97
- allow ( bork_file ) . to receive ( :content_type ) . and_return ( 'text/plain; charset=utf-8' )
98
- expect { uploader . cache! ( bork_file ) } . not_to raise_error
99
- end
100
-
101
- it "rejects the content without charset" do
102
- allow ( bork_file ) . to receive ( :content_type ) . and_return ( 'text/plain' )
103
- expect { uploader . cache! ( bork_file ) } . to raise_error ( CarrierWave ::IntegrityError )
104
- end
105
- end
106
90
end
107
91
108
92
context "when there is a whitelist" do
You can’t perform that action at this time.
0 commit comments