Skip to content

Commit

Permalink
Fix INFO_ARG parsing
Browse files Browse the repository at this point in the history
In split buffer conditions, a buffer is used to accumulate bytes.
After processing, this buffer needs to be reset.

Resolves #270
  • Loading branch information
kozlovic committed May 11, 2016
1 parent 26caad2 commit a8ff707
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func (c *client) parse(buf []byte) error {
var arg []byte
if c.argBuf != nil {
arg = c.argBuf
c.argBuf = nil
} else {
arg = buf[c.as : i-c.drop]
}
Expand Down
10 changes: 9 additions & 1 deletion server/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestSplitDanglingArgBuf(t *testing.T) {
c.parse(pubop[:22])
c.parse(pubop[22:25])
if c.argBuf == nil {
t.Fatal("Expected a nil argBuf!")
t.Fatal("Expected a non-nil argBuf!")
}
c.parse(pubop[25:])
if c.argBuf != nil {
Expand All @@ -337,6 +337,14 @@ func TestSplitDanglingArgBuf(t *testing.T) {
if c.argBuf != nil {
t.Fatalf("Expected c.argBuf to be nil: %q\n", c.argBuf)
}

// INFO_ARG
infoop := []byte("INFO {\"server_id\":\"id\"}\r\n")
c.parse(infoop[:8])
c.parse(infoop[8:])
if c.argBuf != nil {
t.Fatalf("Expected c.argBuf to be nil: %q\n", c.argBuf)
}
}

func TestSplitMsgArg(t *testing.T) {
Expand Down

0 comments on commit a8ff707

Please sign in to comment.