File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1
1
require " spec"
2
2
3
+ private class NoPeekIO
4
+ include IO
5
+
6
+ def read (bytes : Bytes )
7
+ 0
8
+ end
9
+
10
+ def write (bytes : Bytes )
11
+ 0
12
+ end
13
+
14
+ def peek
15
+ raise " shouldn't be invoked"
16
+ end
17
+ end
18
+
3
19
describe " IO::Sized" do
4
20
describe " #read" do
5
21
it " doesn't read past the limit when reading char-by-char" do
@@ -117,6 +133,11 @@ describe "IO::Sized" do
117
133
sized.peek.should eq(Bytes .empty)
118
134
end
119
135
136
+ it " doesn't peek when remaining = 0 (#4261)" do
137
+ sized = IO ::Sized .new(NoPeekIO .new, read_size: 0 )
138
+ sized.peek.should eq(Bytes .empty)
139
+ end
140
+
120
141
it " skips" do
121
142
io = IO ::Memory .new " 123456789"
122
143
sized = IO ::Sized .new(io, read_size: 6 )
Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ module IO
52
52
def peek
53
53
check_open
54
54
55
+ return Bytes .empty if @read_remaining == 0 # EOF
56
+
55
57
peek = @io .peek
56
58
return nil unless peek
57
59
You can’t perform that action at this time.
0 commit comments