1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Merge pull request #433 from pvande/fix/argument-error-on-parse

Avoid calling String#strip on invalid Strings
This commit is contained in:
John Nunemaker 2015-09-20 21:13:27 -04:00
commit 66a0b307bf
2 changed files with 9 additions and 1 deletions

View file

@ -98,7 +98,9 @@ module HTTParty
# @return [Object] the parsed body
# @return [nil] when the response body is nil, an empty string, spaces only or "null"
def parse
return nil if body.nil? || body.strip.empty? || body == "null"
return nil if body.nil?
return nil if body == "null"
return nil if body.valid_encoding? && body.strip.empty?
if supports_format?
parse_supported_format
else

View file

@ -97,6 +97,12 @@ RSpec.describe HTTParty::Parser do
allow(@parser).to receive_messages(body: " ")
expect(@parser.parse).to be_nil
end
it "does not raise exceptions for bodies with invalid encodings" do
allow(@parser).to receive_messages(body: "\x80")
allow(@parser).to receive_messages(supports_format?: false)
expect(@parser.parse).to_not be_nil
end
end
describe "#supports_format?" do