File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed
Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ def params
125125
126126 # Pull out request body params if the content type matches and we're on a POST or PUT
127127 def body_params
128- if [ 'POST' , 'PUT' ] . include? ( request . request_method . to_s . upcase )
128+ if [ 'POST' , 'PUT' ] . include? ( request . request_method . to_s . upcase ) && request . body . size > 0
129129 return case env [ 'CONTENT_TYPE' ]
130130 when 'application/json'
131131 MultiJson . decode ( request . body . read )
Original file line number Diff line number Diff line change @@ -191,6 +191,11 @@ def app; subject end
191191 last_response . body . should == 'Bobby T.'
192192 end
193193
194+ it 'should not convert empty JSON bodies to params' do
195+ put '/request_body' , '' , { 'CONTENT_TYPE' => 'application/json' }
196+ last_response . body . should == ''
197+ end
198+
194199 it 'should convert XML bodies to params' do
195200 post '/request_body' , '<user>Bobby T.</user>' , { 'CONTENT_TYPE' => 'application/xml' }
196201 last_response . body . should == 'Bobby T.'
You can’t perform that action at this time.
0 commit comments