Skip to content
Merged
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
23 changes: 6 additions & 17 deletions test/plugin_helper/test_child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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\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
str = io.read
Expand All @@ -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\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\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
str = io.read
Expand All @@ -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
Expand Down
Loading