You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expect that when I am reading from a file that the encoding should be binary/ASCII-8BIT
require"stringio"# Provides IO interfaceclassIOTest# IO objectdefinitialize(io)@buffer=String.newputs"@buffer: #{@buffer.encoding} in initialize\n\n"@io=ifio.is_a?(String)StringIO.new(io)elsifio.respond_to?(:read)ioelseraiseArgumentError,"#{io.inspect} is neither a String nor an IO object"endend# @param [Integer] length Number of bytes to retrieve# @param [String] outbuf String to be replaced with retrieved data## @return [String, nil]defread(length=nil,outbuf=nil)outbuf=outbuf.to_s.clearputs"Outbuf: #{outbuf.encoding} setup"puts"@buffer: #{@buffer.encoding} setup"@io.read(length,@buffer)puts"Outbuf: #{outbuf.encoding} after read"puts"@buffer: #{@buffer.encoding} after read"outbuf << @bufferputs"Outbuf: #{outbuf.encoding} after outbuf append"puts"@buffer: #{@buffer.encoding} after outbuf append"iflengthlength -= @buffer.lengthbreakiflength.zero?endoutbufunlesslength && outbuf.empty?enddefread_force_outbuf(length=nil,outbuf=nil)outbuf=outbuf.to_s.clearoutbuf.force_encoding(Encoding::BINARY)puts"Outbuf: #{outbuf.encoding} setup"puts"@buffer: #{@buffer.encoding} setup"@io.read(length,@buffer)puts"Outbuf: #{outbuf.encoding} after read"puts"@buffer: #{@buffer.encoding} after read"outbuf << @bufferputs"Outbuf: #{outbuf.encoding} after outbuf append"puts"@buffer: #{@buffer.encoding} after outbuf append"iflengthlength -= @buffer.lengthbreakiflength.zero?endoutbufunlesslength && outbuf.empty?enddefread_force_both(length=nil,outbuf=nil)outbuf=outbuf.to_s.clearoutbuf.force_encoding(Encoding::BINARY)puts"Outbuf: #{outbuf.encoding} setup"puts"@buffer: #{@buffer.encoding} setup"@io.read(length,@buffer)outbuf << @buffer.force_encoding(Encoding::BINARY)puts"Outbuf: #{outbuf.encoding} after read"puts"@buffer: #{@buffer.encoding} after read"outbuf << @bufferputs"Outbuf: #{outbuf.encoding} after outbuf append"puts"@buffer: #{@buffer.encoding} after outbuf append"iflengthlength -= @buffer.lengthbreakiflength.zero?endoutbufunlesslength && outbuf.empty?endendthe_test=IOTest.new(File.new('/some_image_file.jpg'))puts"**************** read without force_encoding"the_test.readputs"**************** END read without force_encoding\n\n"the_test_2=IOTest.new(File.new('/some_image_file.jpg'))puts"**************** read with outbuf force_encoding"the_test_2.read_force_outbufputs"**************** END read with outbuf force_encoding\n\n"the_test_3=IOTest.new(File.new('/some_image_file.jpg'))puts"**************** read with both outbuf/@buffer force_encoding"the_test_3.read_force_bothputs"**************** END read with both outbuf/@buffer force_encoding"
Actual Behavior
reading IO from a file converts buffer to UTF-8 and breaks further downstream file upload processes as a result
The text was updated successfully, but these errors were encountered:
nightsurge
changed the title
IO::Read is changing encoding from ASCII-8BIT to UTF-8
IO::Read is changing encoding from ASCII-8BIT(binary) to UTF-8
Jan 17, 2018
@nightsurge this may be a bug (I did not really study your code very much) but this particular behavior matches MRIs and we generally follow MRI bug-for-bug. Your script did point out a bug in JRuby for sure though #4990.
My suggestion is that you re-open this issue in https://bugs.ruby-lang.org/ and see what they say. IO has a ton of coverage and there might be a specific reason it behave the way it does. M17n is a complicated beast in Ruby :)
I am closing if they say this is a bug we can re-open and target for whichever versions of Ruby they decide to fix it in.
Environment
Provide at least:
Other relevant info you may wish to add:
Expected Behavior
Actual Behavior
The text was updated successfully, but these errors were encountered: