File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed
lib/carrierwave/downloader Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,12 @@ def respond_to?(*args)
23
23
private
24
24
25
25
def filename_from_header
26
- if file . meta . include? 'content-disposition'
27
- match = file . meta [ 'content-disposition' ] . match ( /filename=(?:"([^"]+)"|([^";]+))/ )
28
- match [ 1 ] . presence || match [ 2 ] . presence
29
- end
26
+ return nil unless file . meta . include? 'content-disposition'
27
+
28
+ match = file . meta [ 'content-disposition' ] . match ( /filename=(?:"([^"]+)"|([^";]+))/ )
29
+ return nil unless match
30
+
31
+ match [ 1 ] . presence || match [ 2 ] . presence
30
32
end
31
33
32
34
def filename_from_uri
Original file line number Diff line number Diff line change 6
6
end
7
7
subject { CarrierWave ::Downloader ::RemoteFile . new ( file ) }
8
8
9
- it 'sets file extension based on content-type if missing' do
9
+ before do
10
10
subject . base_uri = URI . parse 'http://example.com/test'
11
11
subject . meta_add_field 'content-type' , 'image/jpeg'
12
+ end
13
+
14
+ it 'sets file extension based on content-type if missing' do
12
15
expect ( subject . original_filename ) . to eq "test.jpeg"
13
16
end
14
17
25
28
end
26
29
end
27
30
31
+ context 'when filename is quoted and empty' do
32
+ let ( :content_disposition ) { 'filename=""' }
33
+
34
+ it "sets file extension based on content-type if missing" do
35
+ expect ( subject . original_filename ) . to eq 'test.jpeg'
36
+ end
37
+ end
38
+
39
+ context 'when filename is not quoted and empty' do
40
+ let ( :content_disposition ) { 'filename=' }
41
+
42
+ it "reads filename correctly" do
43
+ expect ( subject . original_filename ) . to eq 'test.jpeg'
44
+ end
45
+ end
46
+
28
47
context 'when filename is not quoted' do
29
48
let ( :content_disposition ) { 'filename=another_test.jpg' }
30
49
You can’t perform that action at this time.
0 commit comments