Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jarl-dk opened this issue Jan 30, 2025 · 0 comments
Open

Comments

@jarl-dk
Copy link

jarl-dk commented Jan 30, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant