1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Fix handling of invalid encoding with nil log.

Fixes: #469
This commit is contained in:
Andy Brody 2016-05-12 17:39:07 -07:00
parent 8ba78988ad
commit 1bb58653a8
2 changed files with 13 additions and 1 deletions

View file

@ -56,7 +56,9 @@ module RestClient
begin
encoding = Encoding.find(charset) if charset
rescue ArgumentError
RestClient.log << "No such encoding: #{charset.inspect}"
if RestClient.log
RestClient.log << "No such encoding: #{charset.inspect}"
end
end
return unless encoding

View file

@ -98,6 +98,16 @@ describe RestClient do
response.encoding.should eq Encoding.default_external
end
it 'handles invalid encoding' do
stub_request(:get, 'www.example.com').to_return(
body: 'abc', status: 200, headers: {
'Content-Type' => 'text; charset=plain'
})
response = RestClient.get 'www.example.com'
response.encoding.should eq Encoding.default_external
end
it 'leaves images as binary' do
gif = Base64.strict_decode64('R0lGODlhAQABAAAAADs=')