[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:
Hiroshi SHIBATAandClaude Opus 5.5 authored and git committed 2026-10-10 23:54:42 +00:00
1 parent 7ccbe8d06c
commit e1488e6b75
2 files changed
+6 -5

No files matched your search

+4 -5
View File
@@ -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;
}
+2
View File
@@ -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) }