File tree 3 files changed +28
-17
lines changed 3 files changed +28
-17
lines changed Original file line number Diff line number Diff line change @@ -324,7 +324,7 @@ def sanitize(name)
324
324
325
325
def existing_content_type
326
326
if @file . respond_to? ( :content_type ) && @file . content_type
327
- @file . content_type . to_s . chomp
327
+ Marcel :: MimeType . for ( declared_type : @file . content_type . to_s . chomp )
328
328
end
329
329
end
330
330
Original file line number Diff line number Diff line change 274
274
275
275
expect { sanitized_file . content_type } . not_to raise_error
276
276
end
277
+
278
+ it "uses the first one when multiple mime types are given using a semicolon" do
279
+ file = File . open ( file_path ( "bork.txt" ) )
280
+ allow ( file ) . to receive ( :content_type ) { 'image/png; text/html' }
281
+
282
+ sanitized_file = CarrierWave ::SanitizedFile . new ( file )
283
+
284
+ expect ( sanitized_file . content_type ) . to eq ( "image/png" )
285
+ end
286
+
287
+ it "uses the first one when multiple mime types are given using a comma" do
288
+ file = File . open ( file_path ( "bork.txt" ) )
289
+ allow ( file ) . to receive ( :content_type ) { 'image/png, text/html' }
290
+
291
+ sanitized_file = CarrierWave ::SanitizedFile . new ( file )
292
+
293
+ expect ( sanitized_file . content_type ) . to eq ( "image/png" )
294
+ end
295
+
296
+ it "drops content type parameters" do
297
+ file = File . open ( file_path ( "bork.txt" ) )
298
+ allow ( file ) . to receive ( :content_type ) { 'text/html; charset=utf-8' }
299
+
300
+ sanitized_file = CarrierWave ::SanitizedFile . new ( file )
301
+
302
+ expect ( sanitized_file . content_type ) . to eq ( "text/html" )
303
+ end
277
304
end
278
305
279
306
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