Skip to content

Commit e20d7d8

Browse files
committed
Merged with master.
2 parents 0fd1cf7 + aaf5eaa commit e20d7d8

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Next Release
22
============
33

44
* [#201](https://github.com/intridea/grape/pull/201): Rewritten `params` DSL, including support for coercion and validations - [@schmurfy](https://github.com/schmurfy).
5+
* [#205](https://github.com/intridea/grape/pull/205): Fix: Corrected parsing of empty JSON body on POST/PUT - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
56
* [#181](https://github.com/intridea/grape/pull/181): Fix: Corrected JSON serialization of nested hashes containing `Grape::Entity` instances - [@benrosenblum](https://github.com/benrosenblum).
67
* [#203](https://github.com/intridea/grape/pull/203): Added a check to `Entity#serializable_hash` that verifies an entity exists on an object - [@adamgotterer](https://github.com/adamgotterer).
78

lib/grape/endpoint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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)

spec/grape/endpoint_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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.'

0 commit comments

Comments
 (0)