Skip to content

Using HTTP PUT method for binary StringIO body fails with ruby 3.4.x #467

Description

@jarl-dk

There is a difference in StringIO#read behaviour between ruby 3.3.x and 3.4.x.

The difference is illustrated by this:

Ruby 3.3.7:

irb(main):001> RUBY_VERSION
=> "3.3.7"
irb(main):002> binary_io = StringIO.new("\x00".b)
=> #<StringIO:0x00007f50541b8518>
irb(main):003> buf = ''
=> ""
irb(main):004> buf.encoding
=> #<Encoding:UTF-8>
irb(main):005> binary_io.read(1, buf)
=> "\x00"
irb(main):006> buf.encoding
=> #<Encoding:ASCII-8BIT>

Ruby 3.4.0:

irb(main):001> RUBY_VERSION
=> "3.4.0"
irb(main):002> binary_io = StringIO.new("\x00".b)
=> #<StringIO:0x000071c808fafab8>
irb(main):003> buf = ''
=> ""
irb(main):004> buf.encoding
=> #<Encoding:UTF-8>
irb(main):005> binary_io.read(1, buf)
=> "\u0000"
irb(main):006> buf.encoding
=> #<Encoding:UTF-8>

I experience that this new beahaviour affects httpclient when using StringIO as body on PUT requests:

n = io.read([rest, @chunk_size].min, buf)

This may very well also affect other http methods. I have not tried.

The workaround is not to upgrade ruby to 3.4.x

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions