diff --git a/lib/smart_proxy_dynflow/io_buffer.rb b/lib/smart_proxy_dynflow/io_buffer.rb index e22e7ea..e0ffe91 100644 --- a/lib/smart_proxy_dynflow/io_buffer.rb +++ b/lib/smart_proxy_dynflow/io_buffer.rb @@ -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 diff --git a/test/io_buffer_test.rb b/test/io_buffer_test.rb index bc01a96..d31f01d 100644 --- a/test/io_buffer_test.rb +++ b/test/io_buffer_test.rb @@ -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