mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
[ruby/stringio] Convert whence to Integer again in StringIO#seek
d3c5e6d compared whence with Fixnums directly, so a Float or an object with `to_int`, which IO#seek and the JRuby version accept, raised Errno::EINVAL. https://github.com/ruby/stringio/commit/6ecc66a590 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7ccbe8d06c
commit
e1488e6b75
2 files changed
+6
-5
No files matched your search
@@ -960,15 +960,14 @@ strio_seek(int argc, VALUE *argv, VALUE self)
|
||||
if (CLOSED(self)) {
|
||||
rb_raise(rb_eIOError, "closed stream");
|
||||
}
|
||||
switch (whence) {
|
||||
case Qnil:
|
||||
case INT2FIX(0):
|
||||
switch (NIL_P(whence) ? 0 : NUM2LONG(whence)) {
|
||||
case 0:
|
||||
offset = 0;
|
||||
break;
|
||||
case INT2FIX(1):
|
||||
case 1:
|
||||
offset = ptr->pos;
|
||||
break;
|
||||
case INT2FIX(2):
|
||||
case 2:
|
||||
if (NIL_P(ptr->string)) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
@@ -513,6 +513,8 @@ class TestStringIO < Test::Unit::TestCase
|
||||
assert_raise(Errno::EINVAL) { f.seek(-1) }
|
||||
f.seek(-1, 2)
|
||||
assert_equal("4", f.getc)
|
||||
f.seek(-2, 2.0)
|
||||
assert_equal("3", f.getc)
|
||||
assert_raise(Errno::EINVAL) { f.seek(1, 3) }
|
||||
f.close
|
||||
assert_raise(IOError) { f.seek(0) }
|
||||
|
||||
Reference in new issue
Block a user