From 2745985eed772e028a3ed9fe7323d8cfd94ccad2 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Tue, 10 Nov 2026 17:57:39 +0900 Subject: [PATCH 1/2] test_child_process: Exercise scrubbing during transcoding **Which issue(s) this PR fixes**: Fixes #4058 **What this PR does / why we need it**: Ruby 3.3 and later preserve binary input when the external encoding is ASCII-8BIT. Use EUC-JP input with an invalid byte to exercise scrubbing during transcoding to UTF-8. Verify that valid characters survive and that both default and custom replacement characters work. **Docs Changes**: None. **Release Note**: None. Signed-off-by: Takuro Ashie Assisted-by: GPT-6.1 Sol [Codex] --- test/plugin_helper/test_child_process.rb | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/test/plugin_helper/test_child_process.rb b/test/plugin_helper/test_child_process.rb index 1e7eb0eccc..edfdd4b6d8 100644 --- a/test/plugin_helper/test_child_process.rb +++ b/test/plugin_helper/test_child_process.rb @@ -520,15 +520,12 @@ def configure(conf) end test 'can scrub characters without exceptions' do - if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0') - pend "Behaviour of IO#set_encoding is changed as of Ruby 3.3 (#4058)" - end m = Mutex.new str = nil Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do ran = false - args = ['-e', 'STDOUT.set_encoding("ascii-8bit"); STDOUT.write "\xFF\xFF\x00\xF0\xF0"'] - @d.child_process_execute(:t13a, "ruby", arguments: args, mode: [:read]) do |io| + args = ['-e', 'STDOUT.binmode; STDOUT.write "\xA4\xA2\xFF\xA4\xA4"'] + @d.child_process_execute(:t13a, "ruby", arguments: args, mode: [:read], external_encoding: 'euc-jp', internal_encoding: 'utf-8') do |io| m.lock ran = true str = io.read @@ -537,25 +534,19 @@ def configure(conf) sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran m.lock assert_equal Encoding.find('utf-8'), str.encoding - replacement = "\uFFFD" # U+FFFD (REPLACEMENT CHARACTER) - nul = "\x00" # U+0000 (NUL) - expected = replacement * 2 + nul + replacement * 2 - assert_equal expected, str + assert_equal "あ\uFFFDい", str @d.stop; @d.shutdown; @d.close; @d.terminate end end test 'can scrub characters without exceptions and replace specified chars' do - if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0') - pend "Behaviour of IO#set_encoding is changed as of Ruby 3.3 (#4058)" - end m = Mutex.new str = nil replacement = "?" Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do ran = false - args = ['-e', 'STDOUT.set_encoding("ascii-8bit"); STDOUT.write "\xFF\xFF\x00\xF0\xF0"'] - @d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: replacement) do |io| + args = ['-e', 'STDOUT.binmode; STDOUT.write "\xA4\xA2\xFF\xA4\xA4"'] + @d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], external_encoding: 'euc-jp', internal_encoding: 'utf-8', scrub: true, replace_string: replacement) do |io| m.lock ran = true str = io.read @@ -564,9 +555,7 @@ def configure(conf) sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran m.lock assert_equal Encoding.find('utf-8'), str.encoding - nul = "\x00" # U+0000 (NUL) - expected = replacement * 2 + nul + replacement * 2 - assert_equal expected, str + assert_equal "あ?い", str @d.stop; @d.shutdown; @d.close; @d.terminate end end From 1d04045a0e5a7c9ce2110d9cfc56aa524eb5bf48 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Wed, 11 Nov 2026 22:34:09 +0900 Subject: [PATCH 2/2] test_child_process: Cover undefined conversions during scrubbing **Which issue(s) this PR fixes**: Fixes #4058 **What this PR does / why we need it**: Add a well-formed EUC-JP sequence with no Unicode mapping alongside the invalid byte. Both scrubbing tests now cover the invalid and undefined conversion options. **Docs Changes**: None. **Release Note**: None. Assisted-by: GPT-6.1 Sol [Codex] Signed-off-by: Takuro Ashie --- test/plugin_helper/test_child_process.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/plugin_helper/test_child_process.rb b/test/plugin_helper/test_child_process.rb index edfdd4b6d8..412785e0e9 100644 --- a/test/plugin_helper/test_child_process.rb +++ b/test/plugin_helper/test_child_process.rb @@ -524,7 +524,7 @@ def configure(conf) str = nil Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do ran = false - args = ['-e', 'STDOUT.binmode; STDOUT.write "\xA4\xA2\xFF\xA4\xA4"'] + args = ['-e', 'STDOUT.binmode; STDOUT.write "\xA4\xA2\xFF\xA9\xA1\xA4\xA4"'] @d.child_process_execute(:t13a, "ruby", arguments: args, mode: [:read], external_encoding: 'euc-jp', internal_encoding: 'utf-8') do |io| m.lock ran = true @@ -534,7 +534,7 @@ def configure(conf) sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran m.lock assert_equal Encoding.find('utf-8'), str.encoding - assert_equal "あ\uFFFDい", str + assert_equal "あ\uFFFD\uFFFDい", str @d.stop; @d.shutdown; @d.close; @d.terminate end end @@ -545,7 +545,7 @@ def configure(conf) replacement = "?" Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do ran = false - args = ['-e', 'STDOUT.binmode; STDOUT.write "\xA4\xA2\xFF\xA4\xA4"'] + args = ['-e', 'STDOUT.binmode; STDOUT.write "\xA4\xA2\xFF\xA9\xA1\xA4\xA4"'] @d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], external_encoding: 'euc-jp', internal_encoding: 'utf-8', scrub: true, replace_string: replacement) do |io| m.lock ran = true @@ -555,7 +555,7 @@ def configure(conf) sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran m.lock assert_equal Encoding.find('utf-8'), str.encoding - assert_equal "あ?い", str + assert_equal "あ??い", str @d.stop; @d.shutdown; @d.close; @d.terminate end end