Skip to content
Browse files

Merge pull request #34 from nviennot/master

Fix framing issue in the encode_body() method
  • Loading branch information...
2 parents 43a3c3c + dbedd03 commit b3a68ff1b5b7e8eabfe0e84f16ca3780b46cea9e @michaelklishin michaelklishin committed Sep 16, 2013
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/amq/protocol/client.rb
  2. +8 −0 spec/amq/protocol/method_spec.rb
View
2 lib/amq/protocol/client.rb
@@ -177,7 +177,7 @@ def self.encode_body(body, channel, frame_size)
body.force_encoding("ASCII-8BIT") if RUBY_VERSION.to_f >= 1.9
array = Array.new
- while body
+ while body && !body.empty?
payload, body = body[0, limit], body[limit, body.length - limit]
array << BodyFrame.new(payload, channel)
end
View
8 spec/amq/protocol/method_spec.rb
@@ -34,6 +34,14 @@ module Protocol
body_frames.map(&:payload).should == lipsum.split('').each_slice(expected_payload_size).map(&:join)
end
end
+
+ context 'when the body fits perfectly in a single frame' do
+ it 'encodes a body into a single BodyFrame' do
+ body_frames = Method.encode_body('*' * 131064, 1, 131072)
+ body_frames.first.payload.should == '*' * 131064
+ body_frames.should have(1).item
+ end
+ end
end
end
end

0 comments on commit b3a68ff

Please sign in to comment.
Something went wrong with that request. Please try again.