From c8c9856d69e737c41ee7aa1161f18e0c4917d40f Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Thu, 18 Jan 2024 15:14:55 +0100 Subject: [PATCH] Fixes #37060 - Distinguish between bytes and chars --- lib/smart_proxy_dynflow/io_buffer.rb | 2 +- test/io_buffer_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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