Skip to content

Commit

Permalink
Packet#parse_body: don't get a value when total_body_length == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Nov 3, 2009
1 parent c0b1038 commit 2e89596
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/remcached/packet.rb
Expand Up @@ -80,7 +80,11 @@ def self.parse_header(buf)
#
# return:: [String] remaining bytes
def parse_body(buf)
buf, rest = buf[0..(self[:total_body_length] - 1)], buf[self[:total_body_length]..-1]
if self[:total_body_length] < 1
buf, rest = "", buf
else
buf, rest = buf[0..(self[:total_body_length] - 1)], buf[self[:total_body_length]..-1]
end

if self[:extras_length] > 0
self[:extras] = parse_extras(buf[0..(self[:extras_length]-1)])
Expand Down
18 changes: 18 additions & 0 deletions spec/packet_spec.rb
Expand Up @@ -121,5 +121,23 @@
@pkt[:value].should == "World"
end
end

describe :parse_body do
it "should return succeeding bytes" do
s = "\x81\x01\x00\x00" +
"\x00\x00\x00\x00" +
"\x00\x00\x00\x00" +
"\x00\x00\x00\x00" +
"\x00\x00\x00\x00" +
"\x00\x00\x00\x01" +
"chunky bacon"
@pkt = Memcached::Response.parse_header(s[0..23])
s = @pkt.parse_body(s[24..-1])
@pkt[:status].should == 0
@pkt[:total_body_length].should == 0
@pkt[:value].should == ""
s.should == "chunky bacon"
end
end
end
end

0 comments on commit 2e89596

Please sign in to comment.