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

Fixes #37060 - Distinguish between bytes and chars #131

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/smart_proxy_dynflow/io_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def read_available!
def write_available!
until @buffer.empty?
n = @io.write_nonblock(@buffer)
@buffer = @buffer[n..-1]
@buffer = @buffer.bytes.drop(n).pack('c*')
end
rescue IO::WaitWritable # rubocop:disable Lint/SuppressedException
rescue EOFError
Expand Down
6 changes: 6 additions & 0 deletions test/io_buffer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class CustomWaitWritable < RuntimeError
buffer.write_available!
assert_equal buffer.to_s, 'ello'
end

it 'can deal with wide characters' do
buffer.add_data('ラジオで勉強しました')
buffer.write_available! # This would raise an exception
assert_equal buffer.to_s, ''
end
end

describe '#read_available!' do
Expand Down
Loading