From 7292569d3fefacee8dd9cac739a07f4af1a1c808 Mon Sep 17 00:00:00 2001 From: normal Date: Wed, 28 Mar 2018 08:38:21 +0000 Subject: [PATCH] io.c: IO#write without args returns 0 This is consistent with other implementations of .write in openssl and stringio. * io.c (io_write_m): return 0 on argc == 0 [ruby-core:86285] [Bug #14338] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 2 +- test/ruby/test_io.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/io.c b/io.c index cb24b283d2..ebf5743d37 100644 --- a/io.c +++ b/io.c @@ -1678,7 +1678,7 @@ io_writev(int argc, VALUE *argv, VALUE io) static VALUE io_write_m(int argc, VALUE *argv, VALUE io) { - if (argc > 1) { + if (argc != 1) { return io_writev(argc, argv, io); } else { diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index a271c9e677..43c3ed7566 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1287,6 +1287,13 @@ class TestIO < Test::Unit::TestCase assert_empty(err) end + def test_write_no_args + IO.pipe do |r, w| + assert_equal 0, w.write, '[ruby-core:86285] [Bug #14338]' + assert_equal :wait_readable, r.read_nonblock(1, exception: false) + end + end + def test_write_non_writable with_pipe do |r, w| assert_raise(IOError) do