[#108552] [Ruby master Bug#18782] Race conditions in autoload when loading the same feature with multiple threads. — "ioquatix (Samuel Williams)" <noreply@...>
Issue #18782 has been reported by ioquatix (Samuel Williams).
11 messages
2022/05/14
[ruby-core:108713] [Ruby master Bug#18771] IO.foreach/.readlines ignores the 4th positional argument
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2022-05-26 19:37:42 UTC
List:
ruby-core #108713
Issue #18771 has been updated by jeremyevans0 (Jeremy Evans).
I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/5953
----------------------------------------
Bug #18771: IO.foreach/.readlines ignores the 4th positional argument
https://bugs.ruby-lang.org/issues/18771#change-97764
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* ruby -v: 3.0.3
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
The `IO.readlines` method has the following signature:
```
readlines(name, sep, limit [, getline_args, open_args]) → array
```
The last arguments `getline_args`, `open_args` are accepted as keyword arguments, so there are actually 3 positional arguments - `name`, `sep`, and `limit`.
But if the method is called with any 4th positional argument - then it's just ignored. But I would expect an exception to be raised e.g. "ArgumentError: wrong number of arguments (given 4, expected 1..3)"
```ruby
File.readlines('file.txt', "\n", 10)
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, {})
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, {chomp: true})
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, false)
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, nil)
=> ["abc\n", "\n", "def\n"]
```
It's relevant to the `IO.foreach` method as well.
Expected behavior - an ArgumentError exception to be raised.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>