Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/cool.io/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ Coolio_Buffer_read_frame(VALUE self, VALUE data, VALUE mark)

TypedData_Get_Struct(self, struct buffer, &Coolio_Buffer_type, buf);

StringValue(data);
rb_str_modify(data);

if (buffer_read_frame(buf, data, mark_c)) {
return Qtrue;
} else {
Expand Down
19 changes: 19 additions & 0 deletions spec/iobuffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@
expect(data).to eq "foo\nbarbaz"
expect(buffer.to_str).to eq ""
end

it "raises TypeError instead of crashing when data is not a String" do
buffer << "hello world"
expect { buffer.read_frame 12345, " ".ord }.to raise_error(TypeError)
expect { buffer.read_frame nil, " ".ord }.to raise_error(TypeError)
expect { buffer.read_frame [], " ".ord }.to raise_error(TypeError)
end

it "raises FrozenError when data is a frozen String" do
buffer << "hello world"
expect { buffer.read_frame "frozen".freeze, " ".ord }.to raise_error(FrozenError)
end

it "coerces objects responding to #to_str" do
buffer << "foo\nbar"
convertible = Object.new
def convertible.to_str; +""; end
expect(buffer.read_frame convertible, "\n".ord).to eq true
end
end

end
Loading