Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore empty strings when feeding buffers #348

Merged
merged 1 commit into from
Jul 13, 2023
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
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fix a regression where feeding an empty string to an Unpacker would be considered like the end of the buffer.

2023-05-19 1.7.1:

* Fix JRuby 9.4 compatibility.
Expand Down
4 changes: 3 additions & 1 deletion ext/msgpack/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ static inline size_t msgpack_buffer_append_string(msgpack_buffer_t* b, VALUE str
static inline size_t msgpack_buffer_append_string_reference(msgpack_buffer_t* b, VALUE string)
{
size_t length = RSTRING_LEN(string);
_msgpack_buffer_append_long_string(b, string);
if (length > 0) {
_msgpack_buffer_append_long_string(b, string);
}
return length;
}

Expand Down
14 changes: 14 additions & 0 deletions spec/unpacker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ def flush
objects.should == [sample_object] * 4
end

it 'feed and each empty string' do
raw = sample_object.to_msgpack.to_s
objects = []

unpacker.feed("")
unpacker.feed(raw)
unpacker.feed("")

unpacker.each { |c|
objects << c
}
objects.should == [sample_object]
end

it 'feed_each continues internal state' do
raw = sample_object.to_msgpack.to_s * 4
objects = []
Expand Down