[#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:108716] [Ruby master Bug#18770] Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2022-05-26 21:28:49 UTC
List:
ruby-core #108716
Issue #18770 has been updated by jeremyevans0 (Jeremy Evans).
I think both IO#each and StringIO#each behavior is wrong when combining `nil` with `chomp`. My opinion is that a `nil` separator means there is no separator at all, and therefore `chomp` should either raise an error or be ignored if `nil` is the separator. Assuming that ignoring `chomp` is desired behavior for `nil` separator, it follows:
* IO#each behavior for `nil` and `chomp` with a limit is correct. However, IO#each for `nil` and `chomp` without a limit is not, since it removes a final line separator.
* StringIO#each behavior for `nil` and `chomp` is wrong, regardless of whether a limit is used.
This issue is related to String#each_line, but the `nil` and `chomp` combination there is handled correctly, not removing any characters (it doesn't support limit).
Note that Ruby has current tests for the IO#each behavior for `nil` and `chomp` without limit removing the trailing line separator. So the current behavior for that is definitely expected, though I consider it undesirable.
I've added PRs for Ruby (https://github.com/ruby/ruby/pull/5959) and StringIO (https://github.com/ruby/stringio/pull/28) for this.
----------------------------------------
Bug #18770: Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true
https://bugs.ruby-lang.org/issues/18770#change-97767
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* ruby -v: 3.0.3
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
IO's and StringIO's `#each` method (and similar ones - `#gets`, `#readline` etc) behave in a different way in the following case:
- separator is `nil`
- limit is passed
- `chomp: true` passed
In this case `StringIO#each` removes trailing `\n` but `IO#each` does not:
```ruby
StringIO.new("abc\n\ndef\n").each(nil, 2, chomp: true).to_a
#=> ["ab", "c", "\nd", "ef", ""]
File.open('chomp.txt').each(nil, 2, chomp: true).to_a
#=> ["ab", "c\n", "\nd", "ef", "\n"]
```
The file has the same content:
```ruby
File.read('chomp.txt');
#=> "abc\n\ndef\n"
```
Expected behavior - both methods return the same result.
--
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>