Browse files

Merge pull request #110 from timonv/hotfix/null_body

Return nil for 'null' and space filled string bodies
  • Loading branch information...
2 parents 4ccc7bf + 5a891c4 commit 8fe9fda811d4b75851cd3400a50dd44cded9abc7 @jnunemaker committed Nov 1, 2011
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/httparty/parser.rb
  2. +10 −0 spec/httparty/parser_spec.rb
View
4 lib/httparty/parser.rb
@@ -96,9 +96,9 @@ def initialize(body, format)
private_class_method :new
# @return [Object] the parsed body
- # @return [nil] when the response body is nil or an empty string
+ # @return [nil] when the response body is nil, an empty string, spaces only or "null"
def parse
- return nil if body.nil? || body.empty?
+ return nil if body.nil? || body.strip.empty? || body == "null"
if supports_format?
parse_supported_format
else
View
10 spec/httparty/parser_spec.rb
@@ -87,6 +87,16 @@ class MyParser < HTTParty::Parser
@parser.stub(:body => nil)
@parser.parse.should be_nil
end
+
+ it "returns nil for a 'null' body" do
+ @parser.stub(:body => "null")
+ @parser.parse.should be_nil
+ end
+
+ it "returns nil for a body with spaces only" do
+ @parser.stub(:body => " ")
+ @parser.parse.should be_nil
+ end
end
describe "#supports_format?" do

0 comments on commit 8fe9fda

Please sign in to comment.