Skip to content

Commit

Permalink
Do not raise an exception if the body is missing from the response
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Jan 11, 2025
1 parent 9850669 commit a898730
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vcr/structs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def force_encode_string(string, encoding)
end

def try_encode_string(string, encoding_name)
return string if encoding_name.nil?
return string if encoding_name.nil? || string.nil?

encoding = Encoding.find(encoding_name)
return string if string.encoding == encoding
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/vcr/structs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def body_hash(key, value)
expect(i.response).to eq(Response.new(ResponseStatus.new))
end

it 'uses a blank body if it is missing from the response' do
hash['response']['body'] = { 'encoding' => 'US-ASCII' }

i = HTTPInteraction.from_hash(hash)
expect(i.response.body).to eq('')
end

it 'decodes the base64 body string' do
hash['request']['body'] = body_hash('base64_string', Base64.encode64('req body'))
hash['response']['body'] = body_hash('base64_string', Base64.encode64('res body'))
Expand Down

0 comments on commit a898730

Please sign in to comment.