From 0b2613f44309bddae45562c9f3a14ed43e56959b Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 15 May 2023 11:13:51 +0900 Subject: `rb_io_puts` should not write zero length strings. (#7806) --- test/fiber/test_io.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/fiber/test_io.rb b/test/fiber/test_io.rb index de88745e57..c1ad56a8cf 100644 --- a/test/fiber/test_io.rb +++ b/test/fiber/test_io.rb @@ -170,6 +170,34 @@ class TestFiberIO < Test::Unit::TestCase assert_predicate(o, :closed?) end + def test_puts_empty + omit "UNIXSocket is not defined!" unless defined?(UNIXSocket) + + i, o = UNIXSocket.pair + i.nonblock = false + o.nonblock = false + + thread = Thread.new do + # This scheduler provides non-blocking `io_read`/`io_write`: + scheduler = IOBufferScheduler.new + Fiber.set_scheduler scheduler + + Fiber.schedule do + # This was causing a segfault on older Ruby. + o.puts "" + o.puts nil + o.close + end + end + + thread.join + + message = i.read + i.close + + assert_equal $/*2, message + end + def test_io_select omit "UNIXSocket is not defined!" unless defined?(UNIXSocket) -- cgit v1.2.1