Skip to content

Commit

Permalink
Fixes #37060 - Distinguish between bytes and chars
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Jan 18, 2024
1 parent ae01eef commit c8c9856
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit c8c9856

Please sign in to comment.