oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
2.98k stars 179 forks source link

`StringIO` does not set the ASCII-8BIT encoding in `wb` mode #3599

Closed DataWraith closed 3 days ago

DataWraith commented 1 week ago

StringIO does not set the ASCII-8BIT encoding when given the wb mode.

A minimal reproduction using the ghcr.io/graalvm/truffleruby-community Docker image is below.

TruffleRuby 24.0.1

# truffleruby --version
truffleruby 24.0.1, like ruby 3.2.2, GraalVM CE Native [x86_64-linux]
irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> io = StringIO.new(String.new, 'wb')
=> #<StringIO:0x24b18>
irb(main):003:0> io.write("Some Unicode characters: äöüß")
=> 33
irb(main):004:0> io.string
=> "Some Unicode characters: äöüß"
irb(main):005:0> io.string.encoding
=> #<Encoding:UTF-8>

Ruby 3.2.2

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> io = StringIO.new(String.new, 'wb')
=> #<StringIO:0x00007f92a0cc91a8>
irb(main):003:0> io.write("Some Unicode characters: äöüß")
=> 33
irb(main):004:0> io.string
=> "Some Unicode characters: \xC3\xA4\xC3\xB6\xC3\xBC\xC3\x9F"
irb(main):005:0> io.string.encoding
=> #<Encoding:ASCII-8BIT>

Ruby 2.7 through 3.3 and JRuby also seem to return ASCII-8BIT Strings.

andrykonchin commented 1 week ago

Thank you for the report, we'll look into it.