diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-05-26 15:22:28 -0700 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-05-30 12:55:47 +0900 |
commit | 1f82269f4e1bf037e3e5504c6071b905f26fec6f (patch) | |
tree | c83f464c070685629e901a9a0e1d702eb0765853 /test/stringio/test_stringio.rb | |
parent | bb6357cddd5af2c244348e96388a10f7cc6f25b4 (diff) | |
download | ruby-1f82269f4e1bf037e3e5504c6071b905f26fec6f.tar.gz |
[ruby/stringio] Fix each with multiple character string and chomp
Previously, this could result in an infinite loop. Always update
the e pointer in this case, setting w when chomping so the chomped
data is not included in the output.
Fixes [Bug #18769]
https://github.com/ruby/stringio/commit/4bf64d5130
Diffstat (limited to 'test/stringio/test_stringio.rb')
-rw-r--r-- | test/stringio/test_stringio.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 144a9f4292..f14b65a8ea 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -584,6 +584,13 @@ class TestStringIO < Test::Unit::TestCase end end + def test_each_string_sep + f = StringIO.new('a||b||c') + assert_equal(["a||", "b||", "c"], f.each("||").to_a) + f.rewind + assert_equal(["a", "b", "c"], f.each("||", chomp: true).to_a) + end + def test_each f = StringIO.new("foo\nbar\nbaz\n") assert_equal(["foo\n", "bar\n", "baz\n"], f.each.to_a) |