File tree 8 files changed +72
-3
lines changed
8 files changed +72
-3
lines changed Original file line number Diff line number Diff line change 33
33
- Gemfile
34
34
- gemfiles/rack1.gemfile
35
35
- gemfiles/rack2.gemfile
36
+ - gemfiles/rack2_2.gemfile
36
37
- gemfiles/rack_edge.gemfile
37
38
- gemfiles/rails_5.gemfile
38
39
- gemfiles/rails_6.gemfile
@@ -76,15 +77,15 @@ jobs:
76
77
77
78
- name : Run tests
78
79
run : bundle exec rake spec
79
-
80
+
80
81
- name : Run tests (spec/integration/eager_load)
81
82
if : ${{ matrix.gemfile == 'Gemfile' }}
82
83
run : bundle exec rspec spec/integration/eager_load
83
84
84
85
- name : Run tests (spec/integration/multi_json)
85
86
if : ${{ matrix.gemfile == 'gemfiles/multi_json.gemfile' }}
86
87
run : bundle exec rspec spec/integration/multi_json
87
-
88
+
88
89
- name : Run tests (spec/integration/multi_xml)
89
90
if : ${{ matrix.gemfile == 'gemfiles/multi_xml.gemfile' }}
90
91
run : bundle exec rspec spec/integration/multi_xml
Original file line number Diff line number Diff line change 8
8
9
9
* Your contribution here.
10
10
11
+ * [ #2161 ] ( https://github.com/ruby-grape/grape/pull/2157 ) : Handle EOFError from Rack when given an empty multipart body - [ @bschmeck ] ( https://github.com/bschmeck ) .
12
+
11
13
### 1.5.2 (2021/02/06)
12
14
13
15
#### Features
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source 'https://rubygems.org'
6
+
7
+ gem 'rack', '~> 2.2'
8
+
9
+ group :development, :test do
10
+ gem 'bundler'
11
+ gem 'hashie'
12
+ gem 'rake'
13
+ gem 'rubocop', '1.7.0'
14
+ gem 'rubocop-ast', '1.3.0'
15
+ gem 'rubocop-performance', '1.9.1', require: false
16
+ end
17
+
18
+ group :development do
19
+ gem 'appraisal'
20
+ gem 'benchmark-ips'
21
+ gem 'benchmark-memory'
22
+ gem 'guard'
23
+ gem 'guard-rspec'
24
+ gem 'guard-rubocop'
25
+ end
26
+
27
+ group :test do
28
+ gem 'cookiejar'
29
+ gem 'coveralls_reborn'
30
+ gem 'grape-entity', '~> 0.6'
31
+ gem 'maruku'
32
+ gem 'mime-types'
33
+ gem 'rack-jsonp', require: 'rack/jsonp'
34
+ gem 'rack-test', '~> 1.1.0'
35
+ gem 'rspec', '~> 3.0'
36
+ gem 'ruby-grape-danger', '~> 0.2.0', require: false
37
+ end
38
+
39
+ gemspec path: '../'
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ module Exceptions
76
76
autoload :InvalidVersionHeader
77
77
autoload :MethodNotAllowed
78
78
autoload :InvalidResponse
79
+ autoload :EmptyMessageBody
79
80
end
80
81
end
81
82
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Grape
4
+ module Exceptions
5
+ class EmptyMessageBody < Base
6
+ def initialize ( body_format )
7
+ super ( message : compose_message ( :empty_message_body , body_format : body_format ) , status : 400 )
8
+ end
9
+ end
10
+ end
11
+ end
Original file line number Diff line number Diff line change 44
44
" when specifying %{body_format} as content-type, you must pass valid
45
45
%{body_format} in the request's 'body'
46
46
"
47
+ empty_message_body : ' Empty message body supplied with %{body_format} content-type'
47
48
invalid_accept_header :
48
49
problem : ' Invalid accept header'
49
50
resolution : ' %{message}'
50
51
invalid_version_header :
51
52
problem : ' Invalid version header'
52
53
resolution : ' %{message}'
53
54
invalid_response : ' Invalid response'
54
-
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ def initialize(env, **options)
15
15
16
16
def params
17
17
@params ||= build_params
18
+ rescue EOFError
19
+ raise Grape ::Exceptions ::EmptyMessageBody , content_type
18
20
end
19
21
20
22
def headers
Original file line number Diff line number Diff line change @@ -420,6 +420,19 @@ def app
420
420
expect ( last_response . status ) . to eq ( 201 )
421
421
expect ( last_response . body ) . to eq ( 'Bob' )
422
422
end
423
+
424
+ # Rack swallowed this error until v2.2.0
425
+ it 'returns a 400 if given an invalid multipart body' , if : Gem ::Version . new ( Rack . release ) >= Gem ::Version . new ( '2.2.0' ) do
426
+ subject . params do
427
+ requires :file , type : Rack ::Multipart ::UploadedFile
428
+ end
429
+ subject . post '/upload' do
430
+ params [ :file ] [ :filename ]
431
+ end
432
+ post '/upload' , { file : '' } , 'CONTENT_TYPE' => 'multipart/form-data; boundary=foobar'
433
+ expect ( last_response . status ) . to eq ( 400 )
434
+ expect ( last_response . body ) . to eq ( 'Empty message body supplied with multipart/form-data; boundary=foobar content-type' )
435
+ end
423
436
end
424
437
425
438
it 'responds with a 415 for an unsupported content-type' do
You can’t perform that action at this time.
0 commit comments