Bug #6436
closed
Byte counting incorrect in BufferedIO (net/protocol.rb)
Added by jcast (Jeremie Castagna) almost 12 years ago.
Updated over 4 years ago.
Description
BufferedIO's @rbuf counts bytes with String#size, but should use String#bytesize. This creates potential incorrect reading of a HTTP body when changing the encoding of each chuck passed by HTTP#read_body:
http.read_body do |chunk|
chunk.force_encoding "UTF-8"
end
Files
Emacs diff-mode.el provides a function, diff-context->unified.
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
Thanks Jeremie,
Could you add a test to test/net/http/test_buffered_io.rb ?
Nobu, can you review the patch?
--
Yusuke Endoh mame@tsg.ne.jp
- Status changed from Assigned to Closed
It looks like this issue was fixed between Ruby 2.4 and 2.5:
$ ruby24 -rnet/http -e "p Net::HTTP.start('www.falcom.co.jp', 443, :use_ssl=>true){|http| http.request_get('/'){|res| res.read_body{|c| p c.bytesize; c.force_encoding 'UTF-8'}}}"
0
16384
16384
16384
4604
2
5
0
16384
16384
16384
4604
2
5
-e: end of file reached (EOFError)
$ ruby24 -rnet/http -e "p Net::HTTP.start('www.falcom.co.jp', 443, :use_ssl=>true){|http| http.request_get('/'){|res| res.read_body{|c| p c.bytesize}}}"
0
16384
16384
16384
4604
#<Net::HTTPOK 200 OK readbody=true>
$ ruby25 -rnet/http -e "p Net::HTTP.start('www.falcom.co.jp', 443, :use_ssl=>true){|http| http.request_get('/'){|res| res.read_body{|c| p c.bytesize; c.force_encoding 'UTF-8'}}}"
0
16384
16384
16384
4604
#<Net::HTTPOK 200 OK readbody=true>
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0