diff options
| author | Jean byroot Boussier <jean.boussier+github@shopify.com> | 2023-10-05 09:43:59 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-10-05 07:44:08 +0000 |
| commit | f087f2c74c99ec5fed04896d3dc91ff76c2b16b8 (patch) | |
| tree | a66f6c9ab91ac35c6e36df5e474b4a9750daf1e3 /test | |
| parent | 9d58f9382893a71d8badad605879c0120915fbee (diff) | |
[ruby/stringio] StringIO#pread: handle 0 length like IO#pread
(https://github.com/ruby/stringio/pull/67)
Fix: https://github.com/ruby/stringio/issues/66
If length is 0, IO#pread don't even try to read the IO, it simply return
the buffer untouched if there is one or a new empty buffer otherwise.
It also doesn't validate the offset when length is 0.
cc @jdelStrother @kou
https://github.com/ruby/stringio/commit/37e9279337
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
Diffstat (limited to 'test')
| -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 d2d96c5719..cb82841231 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -750,6 +750,13 @@ class TestStringIO < Test::Unit::TestCase assert_raise(EOFError) { f.pread(1, 5) } assert_raise(ArgumentError) { f.pread(-1, 0) } assert_raise(Errno::EINVAL) { f.pread(3, -1) } + + assert_equal "".b, StringIO.new("").pread(0, 0) + assert_equal "".b, StringIO.new("").pread(0, -10) + + buf = "stale".b + assert_equal "stale".b, StringIO.new("").pread(0, 0, buf) + assert_equal "stale".b, buf end def test_size |
