Skip to content

Commit

Permalink
Stop ignoring 4th positional argument to IO.#{foreach,readlines}
Browse files Browse the repository at this point in the history
Fixes [Bug #18771]
  • Loading branch information
jeremyevans committed Jun 9, 2022
1 parent 940c8b0 commit 27eb365
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions io.c
Expand Up @@ -11400,7 +11400,7 @@ rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
struct foreach_arg arg;
struct getline_arg garg;

argc = rb_scan_args(argc, argv, "13:", NULL, NULL, NULL, NULL, &opt);
argc = rb_scan_args(argc, argv, "12:", NULL, NULL, NULL, &opt);
RETURN_ENUMERATOR(self, orig_argc, argv);
extract_getline_args(argc-1, argv+1, &garg);
open_key_args(self, argc, argv, opt, &arg);
Expand Down Expand Up @@ -11495,7 +11495,7 @@ rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
struct foreach_arg arg;
struct getline_arg garg;

argc = rb_scan_args(argc, argv, "13:", NULL, NULL, NULL, NULL, &opt);
argc = rb_scan_args(argc, argv, "12:", NULL, NULL, NULL, &opt);
extract_getline_args(argc-1, argv+1, &garg);
open_key_args(io, argc, argv, opt, &arg);
if (NIL_P(arg.io)) return Qnil;
Expand Down
3 changes: 3 additions & 0 deletions test/ruby/test_io.rb
Expand Up @@ -2596,6 +2596,8 @@ def test_foreach
assert_raise_with_message(IOError, /not opened for reading/, bug6054) do
IO.foreach(t.path, mode:"w").next
end

assert_raise(ArgumentError, "[Bug #18771] [ruby-core:108503]") {IO.foreach(t, "\n", 10, true){}}
}
end

Expand All @@ -2605,6 +2607,7 @@ def test_s_readlines
assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2))
assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
assert_raise(ArgumentError, "[Bug #18771] [ruby-core:108503]") {IO.readlines(t, "\n", 10, true){}}
}
end

Expand Down

0 comments on commit 27eb365

Please sign in to comment.