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

Fix default Net::HTTP encoding in Windows tests.

It turns out that Net::HTTP seems to always use UTF-8 as the default
encoding, even when Encoding.default_external is Encoding::IBM437 (as it
is on Windows/mingw).
This commit is contained in:
Andy Brody 2016-06-19 14:47:58 -04:00
parent b98798e632
commit 0d8f777fec
2 changed files with 7 additions and 5 deletions

View file

@ -8,8 +8,8 @@ module RestClient
# text. This differs from the older RFC 2616 behavior, which specifies # text. This differs from the older RFC 2616 behavior, which specifies
# using ISO-8859-1 for text/* content types without a charset. # using ISO-8859-1 for text/* content types without a charset.
# #
# Strings will effectively end up using `Encoding.default_external` when # Strings will use the default encoding when this method returns nil. This
# this method returns nil. # default is likely to be UTF-8 for Ruby >= 2.0
# #
# @param headers [Hash<Symbol,String>] # @param headers [Hash<Symbol,String>]
# #

View file

@ -88,14 +88,15 @@ describe RestClient do
expect(response.encode('utf-8')).to eq body_utf8 expect(response.encode('utf-8')).to eq body_utf8
end end
it 'defaults to Encoding.default_external' do it 'defaults to the default encoding' do
stub_request(:get, 'www.example.com').to_return( stub_request(:get, 'www.example.com').to_return(
body: 'abc', status: 200, headers: { body: 'abc', status: 200, headers: {
'Content-Type' => 'text/plain' 'Content-Type' => 'text/plain'
}) })
response = RestClient.get 'www.example.com' response = RestClient.get 'www.example.com'
expect(response.encoding).to eq Encoding.default_external # expect(response.encoding).to eq Encoding.default_external
expect(response.encoding).to eq Encoding::UTF_8
end end
it 'handles invalid encoding' do it 'handles invalid encoding' do
@ -105,7 +106,8 @@ describe RestClient do
}) })
response = RestClient.get 'www.example.com' response = RestClient.get 'www.example.com'
expect(response.encoding).to eq Encoding.default_external # expect(response.encoding).to eq Encoding.default_external
expect(response.encoding).to eq Encoding::UTF_8
end end
it 'leaves images as binary' do it 'leaves images as binary' do