mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix ARGF.read(length) short read [Bug #18074]
This commit is contained in:
parent
510c3655c9
commit
8df1ace64a
Notes:
git
2021-08-10 11:33:08 +09:00
2 changed files with 10 additions and 2 deletions
3
io.c
3
io.c
|
@ -12512,8 +12512,7 @@ argf_read(int argc, VALUE *argv, VALUE argf)
|
|||
else if (argc >= 1) {
|
||||
long slen = RSTRING_LEN(str);
|
||||
if (slen < len) {
|
||||
len -= slen;
|
||||
argv[0] = LONG2NUM(len);
|
||||
argv[0] = LONG2NUM(len - slen);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1110,4 +1110,13 @@ class TestArgf < Test::Unit::TestCase
|
|||
assert_raise(TypeError, bug11610) {gets}
|
||||
};
|
||||
end
|
||||
|
||||
def test_sized_read
|
||||
[@t1, @t2, @t3].each { |t|
|
||||
open(t.path, "wb") { |f| f.write "t" }
|
||||
}
|
||||
ruby('-e', "print ARGF.read(3).size", @t1.path, @t2.path, @t3.path) do |f|
|
||||
assert_equal("3", f.read)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue